Content deleted Content added
Simonjwright (talk | contribs) m Updated details of Ada’s integer overflow handling |
Jerryobject (talk | contribs) Small WP:EoS WP:COPYEDITs. WP:LINKs: WP:Disambiguate, updates, fix-cut: underscore, WP:NOPIPEs. Full terms define before WP:ABBReviations. Inline WP:EXTernal links > WP:REFerences. 2nd person WP:YOUs fix-cut. |
||
Line 1:
{{merge|Arithmetic overflow|discuss=Talk:
[[Image:Odometer rollover.jpg|thumb|250px|[[Odometer]] rollover, a mechanical form of integer overflow. All digits are set to the maximum 9 and the next increment of the white digit causes a cascade of carry-over additions setting all digits to 0, but there is no higher digit to change to a 1, so the counter resets to zero. This is ''wrapping''
In [[computer programming]], an '''integer overflow''' occurs when an [[arithmetic]] operation attempts to create a numeric value that is too large to be represented within the available storage space. For
== Origin ==
Line 15:
* 128 bits: maximum representable value 2<sup>128</sup> − 1 = 340,282,366,920,938,463,463,374,607,431,768,211,455
Since an arithmetic operation may produce a result larger than the maximum representable value, a potential error condition may result. In the programming language [[C (programming language)|C
A
<!-- Diagram that illustrates wrapping behavior of integer representation. -->
Line 38:
| [[Java (programming language)|Java]] || NA || ignored
|-
| [[Python (programming language)|Python
|-
| [[Seed7]] || NA || <tt>'''raise''' OVERFLOW_ERROR</tt><ref>[http://seed7.sourceforge.net/manual/errors.htm#OVERFLOW_ERROR Seed7 manual], section 15.2.3 OVERFLOW_ERROR.</ref>
Line 46:
| [[Smalltalk]] || NA || convert to LargeInteger
|-
| [[Swift (programming language)|Swift]] || colspan="2 | Causes error unless using special overflow operators.<ref>The Swift Programming Language. Swift 2.1 Edition. October 21, 2015.</ref>
|-
|}
Line 52:
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.
==
Programming languages implement various mitigation
Run-time overflow detection implementation <code>AddressSanitizer</code> is also available for [[C compiler]]s.
Line 59:
{{Main article|AddressSanitizer}}
List of
* The effects of integer-based attacks for C/C++ and how to defend against them by using subtyping in Efficient and Accurate Detection of Integer-based Attacks<ref>[http://web.archive.org/web/20121010025025/http://www.cs.cmu.edu/~dbrumley/pubs/integer-ndss-07.pdf Efficient and Accurate Detection of Integer-based Attacks]
* [[Computer emergency response team
In languages with native support for [[Arbitrary-precision arithmetic]] and [[type safety]] (such as [[Python (programming language)|Python]] or [[Common Lisp]]), numbers are promoted to a larger size automatically when overflows occur, or exceptions thrown (conditions signaled) when a range constraint exists. Using such languages may thus be helpful to mitigate this issue.
| url = http://random-state.net/features-of-common-lisp.html
| title = Features of Common Lisp
| first = Abhishek | last = Reddy
| date = 2008-08-22
}}</ref><ref>{{Cite book|authorlink=Benjamin C. Pierce |last=Pierce |first=Benjamin C. |title=Types and Programming Languages |publisher=MIT Press |year=2002 |isbn=0-262-16209-1 |url=http://www.cis.upenn.edu/~bcpierce/tapl/}}</ref><ref>{{Cite journal|last=Wright |first=Andrew K. |author2=[[Matthias Felleisen]]
In Java 8, there are overloaded methods, for example like Math#addExact(),<ref>[https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#addExact-int-int- Math#addExact()]
== Example ==
On 30 April 2015, the [[Federal Aviation Authority]] announced it will order [[Boeing 787]] operators to reset its electrical system periodically, to avoid an integer overflow which could lead to loss of electrical power and [[ram air turbine]] deployment, and Boeing is going to deploy a [[software update]] in the fourth quarter.<ref>{{cite news |title= F.A.A. Orders Fix for Possible Power Loss in Boeing 787 |work= [[New York Times]] |date= 30 April 2015 |url= http://www.nytimes.com/2015/05/01/business/faa-orders-fix-for-possible-power-loss-in-boeing-787.html?_r=0}}</ref> The [[European Aviation Safety Agency]] followed on 4 May 2015.<ref>{{cite web |url= http://ad.easa.europa.eu/ad/US-2015-09-07 |work= Airworthiness Directives |title= US-2015-09-07 : Electrical Power - Deactivation |date= {{date|2015-05-04}} |publisher= [[European Aviation Safety Agency]]}}</ref> The error happens after 2³¹ centiseconds ({{#expr:2^31/100/3600/24}} days), indicating a 32
In ''[[Donkey Kong Jr. Math]]'', when
==See also==
Line 92:
==References==
{{
==External links==
|