...
While this statement is true, arithmetic operations in the Java platform require as much caution as in C and C++. Integer operations can result in overflow because Java does not provide any indication of overflow conditions and silently wraps (Java arithmetic throws an exception only on a division by zero). While integer overflows in vulnerable C and C+ programs may result in execution of arbitrary code, in Java, wrapped values typically result in incorrect computations and unanticipated outcomes.
Wiki Markup |
---|
According to the Java Language Specification \[[JLS 03|AA. Java References#JLS 03]\], section 4.2.2 Integer Operations: |
...
If the result of the addition is greater than the maximum value or less than the minimum value that the int
type can represent, then the variable temp
will contain an erroneous result. In Java, wrapped values typically result in incorrect computations and unanticipated outcomes.
Compliant Solution (Bounds Checking)
...