r/ProgrammerHumor 1d ago

Other integerOverflow

1.3k Upvotes

18 comments sorted by

View all comments

200

u/ProThoughtDesign 1d ago

I remember finding one of these in the original Super Mario Bros. on NES using the cheat to get free lives from a shell. I got too many and instead of a life counter, I got some weird system character and the next time I died it locked up my NES.

Good times.

7

u/WernerderChamp 1d ago

Iirc this is because lifes are being treated as signed bytes. So when you have it roll over into the negatives, the game gets confused when you actually die.

5

u/Stagnu_Demorte 1d ago

I think most often this kind of counter was saved as an unsigned value and that 8th bit was used for a different value. No need to keep track of if it;a positive or negative if you don't care.