by muraty · 12y ago · 0 comments
public static int safeAdd(int l, int r) throws OverflowException {
if (r > 0
? l > Integer.MAX_VALUE - r
: l < Integer.MIN_VALUE - r)
throw new ArithmeticException(String.format(
"Integer overflow: %d + %d", l, r));
return l + r;
}https://www.securecoding.cert.org/confluence/display/java/NU...