Integer overflow: Difference between revisions

Content deleted Content added
Fredrik (talk | contribs)
Line 11:
 
A third possibility is that a [[signed integer]] is being used. In such a case, the overflow could not only result in an incorrect value being returned, but that the value may be reported incorrectly as an unexpectedly negative or positive value.
 
In this third case, one can define overflow to be the condition under which the addition of two positive integers (stored in [[two's-compliment]] format) produce a negative result, and likewise when the addition of two negative integers produce a positive result. The hardware on the CPU that detects this is rather simple; just a few logic gates can detect when the sign bit of the [[addend]]s are the same, and when their value doesn't match the sign bit of the [[sum]].
 
==Security ramifications==