Segmentation faults occur when accessing memory which does not belong to your process. Use this tag along with a tag indicating the language and a tag indicating the operating system. Segmentation faults are typically the result of a dereference operation with pointer variables (most often containing an invalid address) or a buffer overflow. The root cause for an invalid pointer value may be far from the location generating the segmentation fault.
Segmentation faults occur when accessing memory which does not belong to your process. They are common and typically the result of:
- using a pointer to something that has been deallocated;
- using an uninitialized hence bogus pointer;
- using a null pointer;
- overflowing a buffer; or
- attempting to write to read-only memory
The error does not arise when manipulating the pointer variable itself (copying or assigning the pointer variable), but when accessing the memory the variable points to (i.e. dereferencing the pointer variable). To generate the segmentation fault, linux-kernel will deliver signal 11 to the process which has made illegal memory access. The default action of having segmentation fault is coredump, generating a coredump file with basic process information.
Since the point where the segmentation fault is triggered may be far from the location where the environment and actions that generate the conditions for the segmentation fault, finding the root cause can be difficult, especially in a complex, multi-threaded application.
Segmentation fault is descriptive phrase from Unix and Linux families of operating systems labeling a general class of behavior in which the operating system detects a memory access by a process outside of the process' assigned memory resulting in the operating system terminating the process.
This behavior requires hardware support for protected memory which may not be available in some microprocessors.
Additional information can be found on...
- What is a segmentation fault?
- Definitive List of Common Reasons for Segmentation Faults
- Wikipedia topic on Segmentation Fault
- Wikipedia topic on Memory Protection
If the program crashed due to
- unauthorized memory access
- using out-of-bound memory location
- using of uninitialized memory
and it has received SIGSEGV
and/or a coredump file is getting generated, mark your questions using this tag.