
...
Code Block | ||
---|---|---|
| ||
public static long intRangeCheck(long value) throws ArithmeticOverflowArithmeticException { if ((value < Integer.MIN_VALUE) || (value > Integer.MAX_VALUE)) { throw new ArithmeticException("Integer overflow"); } return value; } public static int multAccum(int oldAcc, int newVal, int scale) throws ArithmeticException { final long res = intRangeCheck(((long) oldAcc) + intRangeCheck((long) newVal * (long) scale)); return (int) res; // safe down-cast } |
...
INT32-C. Ensure that operations on signed integers do not result in overflow | ||||
INT32-CPP. Ensure that operations on signed integers do not result in overflow | ||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="fdc1a240da116161-068eb928-4c9e4cea-b26b933f-c16101eb089cd1156a7aaf8b"><ac:plain-text-body><![CDATA[ | [ISO/IEC TR 24772:2010 | http://www.aitcnet.org/isai/] | "Wrap-around Error [XYY]" | ]]></ac:plain-text-body></ac:structured-macro> |
CWE-682, "Incorrect Calculation" | ||||
| CWE-190, "Integer Overflow or Wraparound" | |||
| CWE-191, "Integer Underflow (Wrap or Wraparound)" |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8f5f4557b0569cbe-05e65483-47ae46be-a5a78bc3-ab25603c76e51c87d73754b4"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API 06]] | class [ | http://download.oracle.com/javase/6/docs/api/java/util/concurrent/atomic/AtomicInteger.html] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="497c9d830fcbde96-f9388ace-4e024bbd-8d7a9271-9c4e142ef1c1666d27ccf7b3"><ac:plain-text-body><![CDATA[ | [[Bloch 2005 | AA. Bibliography#Bloch 05]] | Puzzle 27: Shifty i's | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f9b78b8b3e995523-c557d9c1-4b024077-a612a762-41c97901f4f6ca2ede074ac4"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | [§4.2.2, "Integer Operations" | http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.2] | ]]></ac:plain-text-body></ac:structured-macro> |
| |||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b80f4909dc4cb85c-199a8ec3-495447a0-b3e28273-c5574cbf2c8a2647c3856963"><ac:plain-text-body><![CDATA[ | [[Seacord 2005 | AA. Bibliography#Seacord 05]] | Chapter 5. Integers | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f590966d634d71dd-5452a9a4-494c474e-b5a68e85-56f6287e1b9a8f8c8f7f0a50"><ac:plain-text-body><![CDATA[ | [[Tutorials 2008 | AA. Bibliography#Tutorials 08]] | Primitive Data Types | ]]></ac:plain-text-body></ac:structured-macro> |
...