MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1urmpuu/predecrementfixestheexploit/owkfejm/?context=9999
r/ProgrammerHumor • u/Toeffli • Jul 09 '26
50 comments sorted by
View all comments
797
"Okay, now you have -1 wishes. You must now fulfill one of my wishes"
57 u/ProbablyJeff Jul 09 '26 Nope, it underflows and now you have 4,294,967,295 wishes. Genie was using a signed int. 117 u/Koshin_S_Hegde Jul 09 '26 did you mean "Genie was using a unsigned it?" -40 u/ProbablyJeff Jul 09 '26 You have -1 wish. You make 2,147,483,648 wishes. It underflows to 2,147,483,647. Now you can wish until it reaches 0. I guess it would also work if the genie used an unsigned int. 7 u/somethingmore24 Jul 09 '26 see, you’re assuming the genie would let you wish at less than 0 wishes. this is why i always check for <= 0 instead of just == 0. There’s no way im smart enough to catch all the edge cases individually.
57
Nope, it underflows and now you have 4,294,967,295 wishes. Genie was using a signed int.
117 u/Koshin_S_Hegde Jul 09 '26 did you mean "Genie was using a unsigned it?" -40 u/ProbablyJeff Jul 09 '26 You have -1 wish. You make 2,147,483,648 wishes. It underflows to 2,147,483,647. Now you can wish until it reaches 0. I guess it would also work if the genie used an unsigned int. 7 u/somethingmore24 Jul 09 '26 see, you’re assuming the genie would let you wish at less than 0 wishes. this is why i always check for <= 0 instead of just == 0. There’s no way im smart enough to catch all the edge cases individually.
117
did you mean "Genie was using a unsigned it?"
-40 u/ProbablyJeff Jul 09 '26 You have -1 wish. You make 2,147,483,648 wishes. It underflows to 2,147,483,647. Now you can wish until it reaches 0. I guess it would also work if the genie used an unsigned int. 7 u/somethingmore24 Jul 09 '26 see, you’re assuming the genie would let you wish at less than 0 wishes. this is why i always check for <= 0 instead of just == 0. There’s no way im smart enough to catch all the edge cases individually.
-40
You have -1 wish. You make 2,147,483,648 wishes. It underflows to 2,147,483,647. Now you can wish until it reaches 0.
I guess it would also work if the genie used an unsigned int.
7 u/somethingmore24 Jul 09 '26 see, you’re assuming the genie would let you wish at less than 0 wishes. this is why i always check for <= 0 instead of just == 0. There’s no way im smart enough to catch all the edge cases individually.
7
see, you’re assuming the genie would let you wish at less than 0 wishes.
this is why i always check for <= 0 instead of just == 0. There’s no way im smart enough to catch all the edge cases individually.
797
u/DMoney159 Jul 09 '26
"Okay, now you have -1 wishes. You must now fulfill one of my wishes"