Fix the Cause, Not the Symptoms

Some years ago, when working on embedded code written in C, I tracked a bug down to a function that looked something like this:

 
int​ process_items(item* item_array, ​int​ array_size)
 
{
 
int​ i;
 
 
/* For some reason array_size is off by one, so fix it up here */
 
array_size++;
 
 
for​(i = 0; i < array_size; i++) {
 
Process item_array[i]
 
}
 
}

The developer in question (whose blushes I will save) had correctly determined, some months earlier, that the bug he was working on was “caused” by a bad value for array_size. However, instead of continuing his analysis to determine why the function was being called with a bad argument, he decided to make the bug “go away” by fixing it up in the function. ...

Get Debug It! now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.