Debuggeration
December 31st, 2006 | No Comments | Filed in ProgrammingNot surprisingly there is a bug in my code. The segfault was a hint. So, like you do I sprayed printf()s all over the place and found a likely bit of code causing the trouble. I was trying to dereference a NULL pointer, so added a bit of code that said “if (!whatever) return”.
Which then shifted the crash up a level, so I attached a debugger and began stepping through the code, jumping over the error several times before remembering what I was doing. Debuggers really need an “undo” or “rewind” option for when you accidentally jump over the line of code causing the crash.
And now I know exactly where my code crashes and why. It crashes on the line where I attempt to call an object’s member function, except the object is really a NULL pointer.
The pointer should be NULL, the problem is the code shouldn’t even be running at this moment in time.
I hate recursive programming, it always bites me somewhere unexpected. Unfortunately it makes sense to parse a recursive data structure using a recursive function.
And I won’t ask why I can’t compare two std::string objects using ==, but .compare() works fine.
