...
Code Block |
---|
|
for (i = 1; i <= 10; i += 2) {
// ...
}
|
Exceptions
EX1: Numerical comparison operators do not ensure loop termination when comparing with Integer.MAX_VALUE
or Integer.MIN_VALUE
.
Code Block |
---|
|
for (i = 1; i <= Integer.MAX_VALUE; i += 2) {
// ...
}
|
It is not sufficient to compare with Integer.MAX_VALUE - 1
when the loop counter is more than 1. To be safe, ensure that the comparison is carried out with (Integer.MAX_VALUE
- counter's value).
Code Block |
---|
|
for (i = 1; i <= Integer.MAX_VALUE - 2; i += 2) {
// ...
}
|
Risk Assessment
Testing for exact values to terminate a loop may result in infinite loops and denial of service.
...