this post was submitted on 31 Jul 2025
450 points (97.5% liked)

Programmer Humor

27215 readers
1349 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
all 34 comments
sorted by: hot top controversial new old
[–] expatriado@lemmy.world 48 points 3 months ago (2 children)

wouldn't 0 be 0 and -1 underflow to 255 if 8 bit container? intentional error to enhance engagement?

[–] Khanzarate@lemmy.world 74 points 3 months ago* (last edited 3 months ago) (2 children)

You're correct but you have an off by 1 error.

First, the genie grants the wish.

NumWishes=0;

Then, having completed the wish, the genie deducts that wish from the remaining wishes.

NumWishes--;

And to complete the thought,

Lastly, the genie checks if the lampholder is out of wishes

If(NumWishes==0) {...}

(255==0) evaluates to False, so we fall past that check.

[–] Dumhuvud@programming.dev 33 points 3 months ago (5 children)

Yeah, but what if the counter gets decremented before the wish gets granted, huh?

[–] SeductiveTortoise@piefed.social 11 points 3 months ago (1 children)
[–] expatriado@lemmy.world 4 points 3 months ago

i think both solutions are valid, since sometimes you pay before and sometimes after receiving the service

[–] Khanzarate@lemmy.world 4 points 3 months ago

Genie in the OP image would've said "OK you now have 0 wishes".

Since he said 255, my interpretation is a valid solution.

Of course, if we're talking hypothetical wish gaining prevention methods, I'd just have a check before,

previous_wishes = wishes;

{Do all the wish things. wishes ends up with a 255 because of our shenanigans}

If(wishes>=previous_wishes) wishes = previous_wishes-1;

;If the current number of wishes isnt less than the old number of wishes, set it to the old number and subtract 1

If(wishes==0) {/*TODO: write function to end wish giving sequence*/}

[–] Szyler@lemmy.world 1 points 3 months ago* (last edited 3 months ago)

You have 3 wishes.

First wish: I wish my last wish would count as me consuming two wishes. Second wish: I wish to have 0 wishes remaining.

First wish puts you down one wish, so ending at 2. Second wish removes one wish, so at one, then wish happens putting you at 0,

then because this second wish now becomes your last, as you have 0 remaining, the first wish then takes effect and consumes another wish, putting you to - 1 and overflowing.

[–] Mesa@programming.dev 1 points 3 months ago

Didn't even get the joke here because this is how I always imagined genie wishes working.

[–] mohab@piefed.social 0 points 3 months ago (1 children)

I would assume this to be the case since you cannot un-utter a wish—once you say it, it is counted as a wish before it's fulfilled.

If the counter is decremented only after the wish is fulfilled, then this means you can go back on wishes because they don't count until they're fulfilled, which goes against the lore.

[–] Khanzarate@lemmy.world 1 points 3 months ago

Nah theres just no process for undoing your submission.

It doesn't matter when it's decremented if you can't interrupt the process, anyway.

In a code sense we pause for input, feed it to the wishmaker function, and pause until the thread returns, then decrement.

We could decrement first, also, but neither violates the rules.

[–] QuazarOmega@lemy.lol 9 points 3 months ago

This is actually genius

[–] hardware26@discuss.tchncs.de 10 points 3 months ago

Genie reduced number of wishes to 0. But by doing so he granted one of the wishes, so it became -1 (255).

[–] savvywolf@pawb.social 31 points 3 months ago (2 children)

I had a visceral reaction to this because obviously the wish count should be decremented before the wish takes place. Even though I can't think up a convincing technical argument for it.

[–] Skullgrid@lemmy.world 4 points 3 months ago

I had a visceral reaction to this because obviously the wish count should be decremented before the wish takes place.

Why? Shouldn't you decrement the limited resource the user has access to in case the thing you are doing fails?

[–] tyler@programming.dev 1 points 3 months ago

You’d need a check to make sure they don’t wish for something not allowed (like more wishes).

[–] AmazingAwesomator@lemmy.world 25 points 3 months ago

Genie: these wishes are of type signed int64. you now have -1 wishes. you owe me a wish; i wish to be free.

[–] palordrolap@fedia.io 21 points 3 months ago (1 children)

Then you find out the genie uses a signed data value and you now owe him a wish. You're not granted magic. You're compelled to grant the wish. The only restrictions on the genie's wish is that it must be within your (soft, squishy) mortal power.

I can imagine you being reset to the point of the genie's wish every time you die (naturally or otherwise) without succeeding. This could well turn into a Groundhog Day type situation.

[–] xav@programming.dev 3 points 3 months ago

Ooh I would gladly avenge everyone who had wishes before me by being very maliciously compliant.

[–] TheFogan@programming.dev 14 points 3 months ago (1 children)

Wouldn't it depend on the order of operations, you'd think even vibe coding a genie would still have the sense to lower the counter before granting the wish.

So logically

Wishes = 3

Make wish count zero.

*wish used, wish count 2

Wish applied, wish count 0

[–] Feathercrown@lemmy.world 7 points 3 months ago (1 children)

It seems logical to decrement after the wish is granted, imo. Just causes issues in this particular case...

[–] TheFogan@programming.dev 6 points 3 months ago (1 children)

Dunno, I know enough duplicate exploits in games to know giving the effect then reducing the item, is a pretty common source of duplication hacks/bugs.

I guess it comes down to which is the designer is more afraid of happening, the chance of a wish being expended but not granted, or granted without expending.

Then again based on disney's aladin, tricking the genie into rescuing him without using a wish, it does seem practical to assume that the genie errors on the side of granting without expending.

[–] abfarid@startrek.website 13 points 3 months ago

Me: I wish you to tell me truthfully, exactly how many wishes I have remaining.
Genie: *crashes*

[–] jedibob5@lemmy.world 10 points 3 months ago

"Subtract 4 wishes"

[–] MonkderVierte@lemmy.zip 10 points 3 months ago (3 children)

Now make it 2.5 wishes. Now 0.9. Now 999.

[–] TheFogan@programming.dev 9 points 3 months ago

Found the QA tester.

[–] libre@badatbeing.social 4 points 3 months ago

Genie API times out due to detected fuzzing

[–] jol@discuss.tchncs.de 3 points 3 months ago

After you made it 0.9 you no longer have enough wishes left.

[–] Ethanol@pawb.social 7 points 3 months ago

Not a computer scientist but (regarding the post title), this is still classified as an integer overflow as the result -1 flows out of the domain your datatype can represent (0-255).
An integer underflow is when two numbers are so close to each other they become indistinct in your representation. For example a number that is so small, a float would represent it as 0.
Love the meme though :)

[–] Geobloke@aussie.zone 6 points 3 months ago

Righto Gandhi, put the nukes away

[–] Taleya@aussie.zone 3 points 3 months ago

You fool, you've unleashed ghandi's thermonuclear rage!

[–] quantenzitrone@lemmings.world 3 points 3 months ago

I'd like yo have '); DROP TABLE Wishes wishes

[–] Jankatarch@lemmy.world 3 points 3 months ago

Id they were optimized to use unsignrd they would be optimized to use 2 bits for 3 wishes rather than 8. You have 3 wishes left.

[–] sun_is_ra@sh.itjust.works 3 points 3 months ago* (last edited 3 months ago)

Should've been "make -1 wishes" 0 is 0

Edit:oh I get it. First the gene fullfill the wish then subtract one from the 0 wishes.