Why buffer overflow doesn't affect to this code?

前端 未结 5 2025
傲寒
傲寒 2021-01-26 15:09

I have the following code:

int main(int argc, char *argv[])
{
    char ch[10];
    printf(\"String 10 max. :: \"); gets( ch );

    printf(\"String: %s\\n\", ch)         


        
5条回答
  •  梦谈多话
    2021-01-26 15:20

    By using memory that you are not supposed to use, you are entering the territory of undefined behavior. It doesn't crash today on your machine. But the behavior could change without warning.

    For what it's worth, when I run the same code on my cygwin shell, I get

    Segmentation fault (core dumped)
    

提交回复
热议问题