段错误总结:
segmentation fault (shortened to segfault), bus error或者access violation一般是由于试图访问CPU无法物理寻址的内存(access memory that the CPU cannot physically address)。Bus error:
引起的原因:- 不存在的地址
- 不对其的访问(unaligned access)
segmentation fault:
当程序试图访问无法访问的内存,或者访问方式不允许时,产生该错误segmentation fault。a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory
location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part
of the operating system).
引起的原因:
- 试图执行一个没有编译完全的程序。不过大部分编译器不允许输出带编译时错误的二进制文件(如exe,elf)。
- 堆溢出(buffer overflow)
- 使用未初始化的指针
- 解引用空指针
- 试图访问程序未拥有的内存
- 试图改写程序未拥有的内存
- 超出栈的大小(runaway recursion or an infinite loop)