Segfault
Noun · Development
Definitions
Segfault, short for segmentation fault, is a runtime error that occurs when a program attempts to access memory that it is not allowed to, such as reading from or writing to an address outside its allocated segments. The operating system's memory management unit (MMU) detects the violation and sends a SIGSEGV signal to the offending process, which typically terminates it. Common causes include dereferencing null or uninitialized pointers, accessing memory after it has been freed (use-after-free), writing past the bounds of an array (buffer overflow), and stack overflow from excessive recursion. Segfaults are one of the most frequent bugs in C and C++ programs, and debugging them often involves tools like GDB, Valgrind, or AddressSanitizer. Languages with managed memory (Java, Python, Go) largely prevent segfaults through bounds checking and garbage collection. Rust eliminates most causes of segfaults at compile time through its ownership and borrowing system.
In plain English: A crash that happens when your program tries to touch memory it should not, usually because of a pointer bug.
Example: "The daemon segfaults every time you pass it a config file with Unicode characters."
Etymology
- 1960s
- Virtual memory systems introduce memory protection. Accessing invalid memory triggers hardware signals.
- 1970s
- Unix formalizes SIGSEGV (signal 11) as the response to segmentation violations. 'Segfault' enters programmer vocabulary.
- 1990s
- Buffer overflows causing segfaults become the most exploited vulnerability class. Stack smashing protectors are introduced.
- 2020s
- Memory-safe languages (Rust, Go) aim to eliminate segfaults. In C/C++ code, AddressSanitizer and Valgrind detect them at development time.
Origin Story
The Crash Named After a Memory Fence
A segfault (segmentation fault) is a hardware-triggered error that occurs when a program tries to access a memory location it is not allowed to reach. The term comes from 'memory segmentation,' a memory management scheme used by early processors where memory was divided into variable-length segments, each with specific access permissions. When a program violated these permissions, the hardware raised a segmentation violation, which the operating system reported as a segmentation fault. The concept dates to the 1960s, with the Multics operating system (developed at MIT, Bell Labs, and GE starting in 1964) being one of the first to implement fine-grained memory segmentation with hardware-enforced protection. When Unix was developed at Bell Labs in the 1970s as a simplified successor to Multics, it inherited the segmentation fault terminology even as the underlying memory management evolved toward paging. On Unix and Linux systems, a segfault triggers a SIGSEGV signal. Common causes include dereferencing null or dangling pointers, accessing freed memory, writing to read-only memory, and stack overflow. For generations of C and C++ programmers, the segfault has been the most dreaded runtime error: it crashes the program immediately, often with minimal diagnostic information, and the root cause can be far removed from the crash location.
Context: Multics / Unix memory management, 1960s-1970s
Fun fact: The infamous 'Segmentation fault (core dumped)' message dumps the process memory to a file called 'core,' named after magnetic core memory, the dominant RAM technology of the 1950s and 1960s. The name persists decades after the technology became obsolete.