Bug fixing

How are bug fixes handled?

Today, I’ll show you how I fixed Bug 412 in DC++’s Bugzilla install.

Step one is of course to try to reproduce the bug report. If you cannot do this, you simply cannot fix the bug. (Because you can’t see it!)

Step two is to try to reproduce this with a stock version. I always modificate my DC++ a little. To avoid it being a bug in my own code, I run a stock version to verify my findings in step one.

Step three is to try to narrow the versions affected. I normally download a version that’s two or three versions old. If I see I can’t reproduce it and know that something changed and I look at the CVS for clues.

Step four can be a hard part. Narrowing the code field down. This mean that I know where it breaks or somewhere around here. Since it’s a visual bug and hard to catch it with a debugger, I cannot use Visual Studio’s smart debugging help by putting out breakpoints throughout the entire source.
Without looking at the source, I know from experience that QueueFrame.cpp/h handle everything that’s visual about the queue. Althought this narrows the field down to just two files, I need to find out in which function is breaking/behaving badly.
So I think about what’s visual here, beside me knowing the bug. Well, it is of course seeing “Files: ” and “Size: “. Since DC++ doesn’t hardcode strings, I know the strings ‘Files’ and ‘Size’ are in StringDefs.cpp. I do a quick search in it, and find ‘FILES’ and ‘SIZE’. Now, by itself that isn’t very helping. But if I do a search in the files I’ve already narrowed down, if can with ease see where I can find it.
So I’ve found where it’s showing a wrong value, but why is it showing me the wrong value? So I look up one line and notice ‘if(dirty) {‘. Now, if you don’t know C++, this means that if ‘dirty’, which is a variable that can only be true or false, is true the following code will be executed. If ‘dirty’ is false, it will not.
“Aha, since this isn’t shown, items aren’t updated then this means dirty can’t be set to true”.
I’m on to something here. I know why it breaks and where.

Step five is quite easy. I need to go back to the bugreport and look at what triggers the bug. It is triggered when something is removed. “Aha. Then that is where dirty isn’t set to true.”
So I do a search for ‘remove’. Unfortunately, I find a whole bunch of places where ‘remove’ is used. So I start to “analyze” the results. “Well, since I’m looking for where files are removed, I ignore all ‘Appendmenu’ stuff. Ah, there’s the function QueueFrame::on(QueueManagerListener::Removed, QueueItem* aQI) where ‘REMOVE_ITEM’ is used. Huh, I’ll try and search for that instead.” Now, I only get three results and the third is used in (the function) QueueFrame::onSpeaker(…). And I look at the different if blocks, ADD_ITEM, REMOVE_ITEM and UPDATE_ITEM is used. And I notice BOOLSETTING(QUEUE_DIRTY) (it is now called BOLD_QUEUE instead of QUEUE_DIRTY) which basically check if you have the option to bold the queue enabled. This must be the correct function and place I immediately think.

Step six. This is the most easiest thing to do when you’re fixing a bug. Writing the code. Especially when you know exactly the cause. The problem was that dirty wasn’t set to true, so all I have to do here is do that. And I do. Right below the check for the bolding option.

Step seven, and the last. Testing your code. This means that you test out the bug again and if you aren’t seeing it anymore you have fixed it!

What I’ve now explained is exactly how the bug was fixed and how all bugs are fixed. Seeing the bug, locating the problem, finding out the cause of the problem, write the fix, test your code, send your patch.

Leave a Reply

Please log in using one of these methods to post your comment:

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: