I have question,
should the below code dump core?
Please debate if yes/no why ?
Code:char a[6]; a[6]='\0';
I have question,
should the below code dump core?
Please debate if yes/no why ?
Code:char a[6]; a[6]='\0';
Last edited by pravlm; 10-01-2010 at 04:57 PM.
It's definitely wrong, but whether it dumps core depends on many factors. In this case, you got unlucky and the bug didn't make itself known. Obviously, it's better if it dumps core because then you know you have a problem.
A stack overflow usually causes a segfault through an indirect chain of events. The invalid memory access itself doesn't usually cause a fault. It's the corruption which happens to the stack which causes things to go haywire later. If the overflow destroys the base link pointer, then when the function returns, the calling function will have a messed up set of variables. If the overflow destroys the return address, the code will jump somewhere unpredictable and possibly crash. In other words, it will probably crash but not immediately on that line of code.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}