Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
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
bgColor#FFCCCC
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
bgColor#ccccff
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.

...