Ever thought you had a bug but then it turned out the code was correct after all?

I just had what I thought was a bug, but looking more closely it turned out it wasn't.

It was a case where I "should" have doing some processing to account for something having changed, but it turned out that the flag was always set anyway in the code that was apparently incorrect. So the code was correct "by accident" not "by design".

4 Likes

Oh yes.

What has really put me in the twilight zone a few times is spotting an obvious bug while looking over some source code. Then proudly, preemptively, fixing that bug. Only to find the program is now broken. Then scratching my head for ages wondering how on Earth is it possible the thing worked in the first place?! At which point I start to feel my sanity slipping away...

Typically it ends up being that there were two bugs but they cancelled themselves out in all the test stations we had.

6 Likes

Yeah, the two major stages of many a debugging session:

  1. Why doesn't this thing work when it clearly should?
  2. Why does this thing work at all when it clearly shouldn't?
9 Likes