Stack corruption in C++

前端 未结 6 914
囚心锁ツ
囚心锁ツ 2020-12-04 22:44

In C++, in which way the stack may get corrupted. One way I guess is to overwriting the stack variables by accessing an array beyond its boundaries. Is there any other way t

6条回答
  •  抹茶落季
    2020-12-04 23:19

    Taking pointers to stack variables is a good way:

    void foo()
    {
      my_struct s;
      bar(&s);
    }
    

    If bar keeps a copy of the pointer then anything can happen in the future.

    Summing up: Stack corruption happens when there's stray pointers pointing to the stack.

提交回复
热议问题