Segfault on stack overflow

前端 未结 6 2170
囚心锁ツ
囚心锁ツ 2021-01-04 08:20

Why does the linux kernel generate a segfault on stack overflow? This can make debugging very awkward when alloca in c or fortran creation of temporary arrays overflows. Sur

6条回答
  •  情话喂你
    2021-01-04 08:47

    A stack overflow does not necessarily yield a crash. It may silently trash data of your program but continue to execute.

    I wouldn't use SIGSEGV handler kludges but instead fix the original problem.

    If you want automated help, you can use gcc's -Wstack-protector option, which will spot some overflows at runtime and abort the program.

    valgrind is good for dynamic memory allocation bugs, but not for stack errors.

提交回复
热议问题