segmentation fault


Segmentation fault
段错误
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

A segmentation fault occurs when 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).
当程序试图访问不允许被访问的内存位置,或试图以未授权的方式访问内存位置时(例如,试图写只读内存位置,或试图修改操作系统部分),就会发生段错误。


Common causes
常见的原因
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following are some typical causes of a segmentation fault:
造成段错误的几种典型的原因:

Attempting to execute a program that does not compile correctly. Some compilers will output an executable file despite the presence of compile-time errors
试图执行未正确编译的程序。某些编译器会不顾编译时错误继续暑促可执行文件。

Dereferencing NULL pointers
解引用空指针

Attempting to access memory the program does not have rights to (such as kernel structures in process context)
试图访问程序无权访问的内存

Attempting to access a nonexistent memory address (outside process's address space)
试图访问不存在的内存地址

Attempting to write read-only memory (such as code segment)
试图写只读内存

A buffer overflow
缓冲区溢出

Using uninitialized pointers
使用未初始化的指针

Generally, segmentation faults occur because a pointer is NULL, or because it points to random memory (probably never initialized to anything), or because it points to memory that has been freed/deallocated/"deleted".
通常,段错误的原因为指针为空,或指向随机内存,或因为指向已释放已被解除分配、或已被删除的内存


pasted from wikipedia


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章