How to find a bug in an application you didn’t write

I want to share with you an experience I had today – I solved a bug…

Although I solve bugs each day as part of my work this bug was different:

On my way back from work today I called a friend to see how he is doing. He is on the way to earning his PhD and has a presentation tomorrow, unfortunately he had a problem – part of his research was an “application” he inherited and that didn’t work as he expected, I didn’t think I could do anything to help solve a bug in an application I knew nothing about but I couldn’t refuse his request so I went to his home to try and help him.

Software Bugs - FastJack

I had a few things going against me:

The Bad

First I don’t understand the application domain (underwater mining simulation), second the application was written badly like only C++ can be abused – it uses global variables, spaghetti code and variables with cryptic short names and finally I do not have the sufficient mathematic background to understand the equations used throughout the code.

The Good

What I did have was a solid understanding of C++ and visual studio 6 (we couldn’t make newer version compile and run the application).

The solution

After glancing the code I understood something – there is no way I can make sense of this code I need to reduce the problem space, so I’ve asked my friend what is the problem he’s having with the application (other then the god awful code), he told me that the form that shows a certain list doesn’t show the correct information.

The form was written using C++/MFC so we found the function that populate the list and debugged the code that provides it with data and we found  an array that had “invalid” data (invalid being –2000 – the number the author of the code decided to use).

Them we’ve looked to where the data was supposed to be inserted into the array (two functions up the stack) and discovered that the array will only be filled with valid data if a certain string was found in the input file. And so after an hour of work we were able to declare that the data was invalid (at least as far as I can tell) and all that was left to do is to request a new input file – this time with the correct information.


The moral of the story is simple – when encountering a difficult bug don’t try to understand all of the application at once divide it to small pieces and find a good starting place (anchor) that you can learn the code from.

and for god sake refactor your code!

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s