I hate that "integer overflows" have become somewhat pop culture because anytime I see someone try to use it in a joke, they use it wrong.

I've even seen people confuse them with stack overflows and be like "my intelligence is so low it stack underflowed and became the max of an integer value!"

Or "It overflowed and became zero again" ah, I guess it happened to be unsigned and overflowed by precisely 1 then eh?

So cringe

  • 2
    Now I want to see an actual stack underflow 😆
  • 2
    @Lensflare just pop an empty stack.
  • 0
    @Lensflare in low-level areas where a stack really matteres, a stack overflow is not fantasy.
  • 0
    @IntrusionCM not a problem for the implementations of stack that I have ever worked with. It just does the empty check automatically.
  • 0
    @AlgoRythm yeah but I want to see a stack *underflow* 😉
  • 2
    @Lensflare I meant underflow in that comment

    The stack is usually just a block of memory with an integer pointer acting as a bookmark. Popping the stack just decrements the pointer. So if you decrement the pointer past zero it will underflow.

    Popping an empty stack can be problematic especially in lower level implementations
  • 0
    Yeah I agree.

    What I meant was seeng an actual stack underflow. Like the exceptions that you get in higher languages like Java and C# when an overflow happens. The exceptions also have the name "overflow" in them.

    In the case of stack overflows, the name "overflow" can be found in the printed stack trace as well.

    The same higher languages will probably make all kind of checks to prevent a stack underflow from happening directly in the data structure. So, we won’t see them.

    In lower languages like C++ they can happen but I guess you’ll never see the actual name "underflow". Because it will be just a crash or it will manifest in data corruption or bugs.
  • 1
    @Lensflare in C# it results in an InvalidOperationException

    Java has its own specific EmptyStackException

    Popping an empty array in JS just returns undefined

    C++ just segfaults
  • 0
    Swift’s standard data types is my favorite:

    It does nothing and returns nil instead of the value at the top.
    Similar to JS, I suppose.
  • 1
    @IntrusionCM Quantum physics forbids this
  • 2
    @Lensflare I wouldn't take JS as an example reference, cause we all know JS is bonkers.

    But yes, the implementation needs to either not validate properly or (e.g. in the wonderful world of asynchronous / simultaneous access) an lock or similar protection is missing / erroneously implemented.

    @PonySlaystation I'm too dumb for shit like that. Should the smart kids play with their spins, quarks and whatever else they toy with.
  • 1
  • 2
    @PonySlaystation lalalalala *emotional support system encountered an stack underflow, no resources available for consumption*
  • 1
    @IntrusionCM JS has to do *something* right, if just by chance. But most of the time when it looks right, on a closer look, it’s fundamentally broken or a workaround on a workaround.
  • 1
    @Lensflare you just described what it does right. Easy on the surface, clusterfuck exponentially beneath.
Add Comment