• Ethanol@pawb.social
    link
    fedilink
    English
    arrow-up
    4
    arrow-down
    1
    ·
    14 hours 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 :)

  • Jankatarch@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    14 hours 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.

  • expatriado@lemmy.world
    link
    fedilink
    arrow-up
    44
    ·
    24 hours ago

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

    • Khanzarate@lemmy.world
      link
      fedilink
      arrow-up
      64
      ·
      edit-2
      24 hours ago

      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.

          • expatriado@lemmy.world
            link
            fedilink
            arrow-up
            3
            ·
            13 hours ago

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

        • Khanzarate@lemmy.world
          link
          fedilink
          arrow-up
          3
          ·
          20 hours 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*/}

        • mohab@piefed.social
          link
          fedilink
          English
          arrow-up
          1
          arrow-down
          1
          ·
          21 hours ago

          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.

          • wheezy@lemmy.ml
            link
            fedilink
            arrow-up
            3
            ·
            edit-2
            19 hours ago

            Well, not entirely. There are cases for which a person utters the wish and it is not counted. “I wish for a million wishes!”

            The standard is for the genie to explain the exceptions but not count that as a wish.

            Now, it could decrement the count after this check. But just decrementing the count before verification would be sloppy.

            But, then again, basic verification would also include checking that wishes_remaining <= MAX_WISHES.

            Which, I think is a pretty standard check for genie’s. Given that that constant has remained at 3 since their beta days and exceptions are thrown for violations of this rule.

          • Khanzarate@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            21 hours 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.

  • SavvyWolf@pawb.social
    link
    fedilink
    English
    arrow-up
    30
    ·
    23 hours ago

    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.

    • balsoft@lemmy.ml
      link
      fedilink
      arrow-up
      14
      ·
      23 hours ago

      If there’s parallelism/async involved, then there definitely is an argument to decrement first, execute later. Otherwise you could make a wish for the genie to just wait for an hour and then make as many wishes as you want within that hour.

      • Brekky@lemmy.world
        link
        fedilink
        arrow-up
        3
        ·
        23 hours ago

        But how can you decrement a future dated wish, since you can’t guarantee nothing will happen that prevents the genies ability from executing said wish? E.g. i mean like telling the Genie to do something 5 days from now, not your example which would begin immediately after making said wish.

        • CrackedLinuxISO@lemmy.dbzer0.com
          link
          fedilink
          English
          arrow-up
          2
          ·
          edit-2
          17 hours ago

          I always thought that wish-granting is instant, even if the effects of that wish are delayed.

          So if I wish for something to happen in 5 days, it’s granted in the moment and guaranteed to happen. That raises a question though: Can I wish to cancel a wish I have already made, but whose effect has not yet taken hold? On its face, this should be possible, but if we take it as a given that all valid wishes are always granted at the moment of utterance, then it might be physically/psychologically impossible for me or anyone else to revoke the wish before its IRL effect is complete.

        • balsoft@lemmy.ml
          link
          fedilink
          arrow-up
          4
          ·
          22 hours ago

          You decrement the wish counter first, execute the action (which includes waiting those 5 days), and if it fails you increment the counter back. Something like this:

          wishes = wishes - 1;
          executeWish(wish).unwrap_or_else(|_| { wishes = wishes + 1; })?
          

          This way if the action fails in the future, you get a wish back and can ask something else.

    • Skullgrid@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      23 hours 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?

  • TheFogan@programming.dev
    link
    fedilink
    English
    arrow-up
    15
    ·
    21 hours ago

    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
      link
      fedilink
      English
      arrow-up
      7
      ·
      19 hours ago

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

      • TheFogan@programming.dev
        link
        fedilink
        English
        arrow-up
        6
        ·
        18 hours ago

        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.

  • palordrolap@fedia.io
    link
    fedilink
    arrow-up
    21
    ·
    22 hours ago

    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
      link
      fedilink
      arrow-up
      3
      ·
      20 hours ago

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

  • sun_is_ra@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    22 hours 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.