jump to navigation

Breathtaking Bugs! June 20, 2006

Posted by gordonwatts in computers, physics.

I’ve been programming for years now. I think I was about 7 or something when I wrote my first one (FORTRAN, using teco as the editor). But still, I can still lay out some doozies when it comes to bugs:

while (i != _btagdict.end()) {
  const TMBBTag *result = GetBTag(i->first);
  if (result != 0) { 
     return result;

That, my friends, is a perpetual motion machine! I forgot the “++i” at the end of the loop there to advance i. Otherwise it will keep re-checking the same thing. This bug existed at the heart of some check and b-tagging code. I’m amazed it has been in cvs for almost 3 weeks and no one stumbled across it!



1. Kevin - June 24, 2006

Thats not so bad.
I spent 2 days going through every line of my code trying to figure out why my simple linear chi-squared fit always had a chi2 in the > 10^5. A few hundred lines of cout statements and reruning the program more times than I can count revealed that i accidentally defined an angle (in radians) as a integer rather than a double or a float. So it could never converge, it just did 50 itterations every time and told me my angle was 0 with some huge chi2.
Of course if I had been looking at someone else’s code I would have found it in a few minutes, but for some reason it is always 10 times harder to find the bugs in your own code. I guess you just get stuck in a mind set of where it should be and don’t look for the obvious things…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: