Integer overflow: Difference between revisions

Content deleted Content added
m Reverted edits by 2602:306:31D9:4AA0:D89B:4767:5301:D017 (talk) (HG) (3.3.2)
Acb146 (talk | contribs)
Referenced the C language standard which defines the term overflow as never applying to unsigned operations. Added MATLAB and Simulink to the table of language examples.
Line 5:
The most common result of an overflow is that the least significant representable bits of the result are stored; the result is said to ''wrap'' around the maximum (i.e. modulo power of two).
 
An overflow condition givesmay incorrectgive results and,leading particularlyto unintended behavior. In particular, if the possibility has not been anticipated, overflow can compromise a program's reliability and [[software security|security]].
 
For some applications, such as timers and clocks, wrapping on overflow can be desirable. The C11 standard states that for unsigned integers modulo wrapping is the defined behavior and the term overflow never applies "a computation involving unsigned operands can never overflow." <ref>[https://webstore.ansi.org/RecordDetail.aspx?sku=ISO%2FIEC%209899:2011&msclkid=2f0af3a2b5ca143c9285a9f8e8f6b3e1&utm_source=bing&utm_medium=cpc&utm_campaign=Campaign%20%231&utm_term=ISO%2FIEC%209899%3A2011&utm_content=iso-iec ISO C11 Standard]</ref>
 
On some processors like [[graphics processing unit]]s (GPUs) and [[digital signal processor]]s (DSPs) which support [[saturation arithmetic]], overflowed results would be "clamped", i.e. set to the minimum or the maximum value in the representable range, rather than wrapped around.
Line 52 ⟶ 54:
|-
| [[JavaScript]] || colspan="2" | all numbers are [[Double-precision floating-point format|double-precision floating-point]]
|-
| [[MATLAB]] || colspan="2" | Builtin integers saturate. Fixed-point integers configurable to wrap or saturate
|-
| [[Python (programming language)|Python]] 2 || N/A || convert to <tt>long</tt> type (bigint)
Line 58 ⟶ 62:
|-
| [[Scheme (programming language)|Scheme]] || N/A || convert to bigNum
|-
| [[Simulink]] || colspan="2" | configurable to wrap or saturate
|-
| [[Smalltalk]] || N/A || convert to LargeInteger
Line 123 ⟶ 129:
*[http://www.cs.utah.edu/~regehr/papers/tosem15.pdf Understanding Integer Overflow in C/C++]
*[https://www.allaboutcircuits.com/textbook/digital/chpt-2/binary-overflow/ Binary Overflow – Binary Arithmetic]
*[https://webstore.ansi.org/RecordDetail.aspx?sku=ISO%2FIEC%209899:2011&msclkid=2f0af3a2b5ca143c9285a9f8e8f6b3e1&utm_source=bing&utm_medium=cpc&utm_campaign=Campaign%20%231&utm_term=ISO%2FIEC%209899%3A2011&utm_content=iso-iec ISO C11 Standard]
 
[[Category:Software bugs]]