Wiki Markup |
---|
If a while or for statement uses a loop counter, and increments or decrements it by more than one, it should use a numerical comparison operator to terminate the loop. This prevents the loop from running away, either forever, or until the counter wraps around and reaches the final value \[[INT34-J. Perform explicit range checking to ensure integer operations do not overflow]\]. |
Noncompliant Code Example
...
This rule appears in the C++ Secure Coding Standard as MSC21-CPP. Use inequality to terminate a loop whose counter changes by more than one.
References
Wiki Markup |
---|
\[[INT34-J. Perform explicit range checking to ensure integer operations do not overflow]\]
\[[JLS 05|AA. Java References#JLS 05]\] 15.20.1 Numerical Comparison Operators <, <=, >, and >= |