1

Introducing the quantum symbol.

I have a function throwing an error when passed a vector which has an unexpected size.
When I use the debugger and try to watch said vector for write access, the code which failed at some point just does… things. I have no idea what it is doing instead of failing but it is doing it gladly. It's not even paused, at least for the debugger.

Now I know why they said C++ is challenging to debug.

Comments
  • 0
    Is your code threaded ? I've seen that countless times where the debugger is all it took to break deadlocks.
  • 1
    @devphobe There's no threading in my code.
    Also the weird behavior happens only when the vector is observed, when it's removed from the watches the code crash as expected
  • 0
    @CodeTalker I wish I hadn't given up C++ for easier languages. Good luck, I'd love to know what it turns out to be.
  • 3
    Out of bounds access can work or crash, depending on what's before or behind the buffer. The memory layout in debugging mode is usually different so that sometimes, things don't crash because non-essential stuff is garbled up.
  • 1
    @Fast-Nop This.

    If things change in different environments, look at how the environments differ. It sounds like you're looking at a buffer overflow issue, which inherently means undefined behavior. Check the length first!

    As an example: if you're using null-terminated cstrings, check for the terminator and fail/die if it's nonzero or missing. And then check where your memory is getting allocated/set!
  • 1
    @Fast-Nop @Root @devphobe for example something I ran into with Microsoft c/c++ is that (If I remember correctly!) In debug mode, memory is initialized to 0 in some cases, but not in production.
  • 1
    @AlgoRythm Makes sense. Automatically zeroing out memory is a waste of cycles. Shouldn't happen in debug if it doesn't happen at runtime, though.

    However, the differing memory layout @Fast-Nop mentioned absolutely makes sense!
  • 1
    @Fast-Nop Well I badly addressed it: the code doesn't crash actually, I made a check for the function that throws an error if the vector is bigger than a defined size, so I don't think there's a buffer overflow
  • 0
    Use valgrind to spot any memory errors :) Tough with C++ but might help!
  • 0
    Ah, the dreaded "Heisenbug"
Add Comment