|
Explanation for how it was working so far!!!
Hi all
Recently we got an error unearthed which was existing long since in our production code. Let me explain the problem..It was something like this...
char source[20] = "1234567890123456789";
char destination[10];
sprintf(destination,"%9s",source);
The person who coded perhaps had a perception that if he uses the %9s convertion specification, only the 9 characters will be taken from the source string. We know very well that it causes the sprintf to write beyond the allocated memory of destination string. But the problem is like this code is running in production for so long with out giving any issues. Recently when we did some changes in the code, all of a sudden it started behaving abnormal and found this is the cause of error and raised the alarm. Now the question we have to answer is "If it is an error, then how come the same code was running in production for years with out any ERROR?" Please, experts over there.. help us to explain so that a lay man can also understand.
I mean, though I and many around me are sure it is an error, we don't have a convinsing reason/answer for the question "Why the code with the ERROR was working well for such a long time!!" More over we cannot just escape by answeing like - it is a case of memory overwrite which may result in inconsistent behaviour and all - So please help with a STRONG and convincing answer which we can present to any one.
Last edited by bobbyjohnz; 06-14-2006 at 03:15 AM..
|