Integer overflow: Difference between revisions

Content deleted Content added
rm non-RS
Line 157:
 
Overflow bugs are evident in some computer games. In the arcade game ''[[Donkey Kong (video game)|Donkey Kong]]'', [[Kill screen|it is impossible to advance past level 22]] due to an integer overflow in its time/bonus. The game takes the level number a user is on, multiplies it by 10 and adds 40. When they reach level 22, the time/bonus number is 260, which is too large for its 8-bit 256 value register, so it resets itself to 0 and gives the remaining 4 as the time/bonus – too short to finish the level. In ''[[Donkey Kong Jr. Math]]'', when trying to calculate a number over 10,000, it shows only the first 4 digits. Overflow is the cause of the famous [[kill screen|"split-screen" level]] in ''[[Pac-Man]]''.<ref>{{cite web|url=http://home.comcast.net/~jpittman2/pacman/pacmandossier.html|title=The Pac-Man Dossier|author=Pittman, Jamey}}</ref> The notorious [[Nuclear Gandhi]] bug in [[Civilization (video game)|Civilization]] was purportedly caused by an integer underflow which occurred when the game attempted to subtract 2 from Gandhi's default aggression level of 1, setting it to 255, nearly 26 times higher than the normal maximum of 10. ([[Sid Meier]] claimed in an interview that this was, in fact, intentional.) Such a bug also caused the "Far Lands" in ''[[Minecraft]]'' which existed from the Infdev development period to Beta 1.7.3; it was later fixed in Beta 1.8 but still exists in the Pocket Edition and Windows 10 Edition versions of ''Minecraft''.<ref>{{cite web|url=http://minecraft.gamepedia.com/Far_Lands|title=Minecraft Gamepedia Page|author=Minecraft Gamepedia}}</ref> In the [[Super Nintendo Entertainment System|Super NES]] game [[Lamborghini American Challenge]], the player can cause their amount of money to drop below $0 during a race by being fined over the limit of remaining money after paying the fee for a race, which glitches the integer and grants the player $65,535,000 more than it would have had after going negative.<ref>Archived at [https://ghostarchive.org/varchive/youtube/20211205/aNQdQPi0xMo Ghostarchive]{{cbignore}} and the [https://web.archive.org/web/20190726012137/https://www.youtube.com/watch?v=aNQdQPi0xMo&t=17m55s Wayback Machine]{{cbignore}}: {{cite web| url = https://www.youtube.com/watch?v=aNQdQPi0xMo&t=17m55s| title = Lamborghini American Challenge SPEEDRUN (13:24) | website=[[YouTube]]}}{{cbignore}}</ref> A similar glitch occurs in [[S.T.A.L.K.E.R.: Clear Sky]] where the player can drop into a negative amount by fast travelling without sufficient funds, then proceeding to the event where the player gets robbed and has all of their currency taken away. After the game attempts to take the player's money away to an amount of $0, the player is granted 2147482963 in game currency.<ref>{{Cite web|url=https://steamcommunity.com/app/20510/discussions/0/1484358860942756615/|title = Money glitch :: S.T.A.L.K.E.R.: Clear Sky General Discussions}}</ref>
 
In the data structure of [[Pokémon]] in the Pokémon games, the number of gained Experience Points is stored in a 3-byte integer. However, in the first and second generations, the Medium Slow experience group, which requires 1,059,860 Experience Points to reach level 100, is calculated to have -54 Experience Points at level 1 (a level that is not usually encountered during normal play). Due to the integer being unsigned, the value turns into 16,777,162. If the Pokémon gets less than 54 Experience Points in a battle, then the Pokémon will instantaneously jump to level 100.<ref>[[bulba:Pokémon data structure in Generation I|Pokémon data structure in Generation I]]</ref><ref>[[bulba:Pokémon data structure in Generation II|Pokémon data structure in Generation II]]</ref><ref>[[bulba:Pokémon data structure in Generation III|Pokémon data structure in Generation III]]</ref><ref>[[bulba:Pokémon data structure in Generation IV|Pokémon data structure in Generation IV]]</ref>{{Unreliable source?|reason=Is Bulbapedia a reliable source?|date=January 2021}}
 
[[File:Error message due to an integer signedness bug in the stack setup code of MASM 1.00.gif|thumb|An integer signedness bug in the stack setup code emitted by the Pascal compiler prevented Microsoft / IBM MACRO Assembler Version 1.00 (MASM), a DOS program from 1981, and many other programs compiled with the same compiler, to run under some configurations with more than 512 KB of memory.]]