Unable to locate the Bug

Posted by tzenes on Stack Overflow See other posts from Stack Overflow or by tzenes
Published on 2010-02-12T01:53:07Z Indexed on 2010/05/31 2:52 UTC
Read the original article Hit count: 268

Filed under:
|
|

I was recently on The Daily WTF when I came across this old post. In it the author mentions that one of the programmers changed this code:

int main (int argc, char **argv) 
{ 
  int x;
  char data_string[15];
  ...
  x = 2;
  strcpy(data_string,"data data data");
  ...
}

To this code:

int main (int argc, char **argv) 
{
  int x = 2;
  char data_string[15] = "data data data";
  ...
}

The author goes on to mention:

[the coder] changed every single variable to be initiated on the stack

For the life of me I cannot see how this change could be harmful, and I am worried that it is a lapse in my C knowledge. What is the WTF?

© Stack Overflow or respective owner

Related posts about c

    Related posts about stack