An Unusual Bug

It was a routine software testing session. The code seemed to work overall. But in the middle of test run, something was wrong and the error messages seemed to be bigger than normal and hard to understand. On deeper analysis it turned out to be a string concatenation problem.

The statement causing problem was something like this,

str = str1 str2 str3

Somehow str2 was coming on top of str1 (in the print statement for str). Why should str2 “overwrite” str1?

On replacing str2 with some other string, it was working fine. Just this particular string, str2 was causing the problem. And str2 was coming over a communication channel.

What did you say? It is coming on the network. Then the enlightenment dawned. Does str2 have a carriage return, CR, at the end, or somewhere close to end? It sure does.

So str2 was not overwriting str1. It was just appearing like that. It was a situation when the machine pulled up a fast one on me.

Maybe, if I had used a debugger instead of relying on print statements, I would have seen the contents of four string in hex and understood.

Life is amazing. One never stops to learn.

Tags: code, concatenation, CR, overwrite, Software, string, testing

Leave a Reply