Integer overflow: Difference between revisions

Content deleted Content added
Line 17:
 
When an arithmetic operation produces a result larger than the maximum above, an integer overflow causes the number to be reduced [[modular arithmetic|modulo a power of two]], producing an unexpected result (a ''wrap around'').
 
{{anchor|Security ramifications}}
In some situations, a program may make the assumption that a variable always contains a positive value. If the variable has a [[Signed number representations|signed integer]] type, an overflow can cause its value to wrap and become negative. This overflow violates the program's assumption and may lead to unintended behavior. Similarly, subtracting from a small unsigned value may cause it to wrap to a large positive value which may also be an unexpected behavior. Multiplying or adding two integers may result in a value that is non-negative, but unexpectedly small. If this number is used as the number of bytes to allocate for a buffer, the buffer will be allocated unexpectedly small, leading to a potential buffer overflow.