part of c programming
this example uses sph-sc-lib memreg
#include#include #include "sph/memreg.c" int main(void) { memreg_init(2) int *data_a = malloc(12 * sizeof(int)) if (!data_a) goto exit memreg_add(data_a) char *data_b = malloc(20) if (!data_b) goto exit memreg_add(data_b) if (is_error) goto exit exit: memreg_free return 0 }
Segmentation fault (core dumped)
Program received signal SIGSEGV, Segmentation fault. 0x000000000040113a in memcpy ()
what it usually means:
a load or store used an address that is not mapped in the process address space
or an address is mapped but violates permissions (for example write to read-only page)
likely causes in memory-management terms:
dereference of a zero pointer
use-after-free: freed chunk later reused, pointer retained, dereferenced after allocator repurposed or unmapped it
out-of-bounds write: overwrote a pointer or vtable-like function pointer, later control/data flow jumps to garbage address
returning or storing the address of a stack object past its lifetime, then dereferencing it later
calling free on a non-heap pointer: allocator metadata corrupted, later allocator activity dereferences junk and crashes
Bus error (core dumped)
what it usually means:
the address is mapped, but the access is invalid at the hardware or kernel level
likely causes:
misaligned access on architectures that fault on alignment (less common on x86_64, more common elsewhere)
mmapped file truncation: accessing a page past the new end of file triggers SIGBUS
wild pointer that happens to point into a mapped region with constraints (alignment or device mapping)
Illegal instruction (core dumped)
what it usually means:
CPU tried to execute bytes that are not a valid instruction stream for the current mode
likely causes:
heap/stack corruption overwrote a return address or function pointer, control flow jumps into non-code bytes
use-after-free jumped through a function pointer inside an object whose storage was recycled
double free or corruption (!prev) Aborted (core dumped)
free(): invalid pointer Aborted (core dumped)
munmap_chunk(): invalid pointer Aborted (core dumped)
malloc(): corrupted top size Aborted (core dumped)
free(): invalid next size (fast) Aborted (core dumped)
corrupted size vs. prev_size Aborted (core dumped)
what it usually means:
the allocator detected internal invariants were violated and deliberately terminated
likely causes by message class:
"double free":
"invalid pointer" / "munmap_chunk(): invalid pointer":
"corrupted top size" / "invalid next size" / "corrupted size vs prev_size":
out-of-bounds write that hit allocator metadata adjacent to the user region
write-after-free into a freed chunk that is now on a free list
buffer overflow in one allocation corrupting the header of the next allocation
diagnostic trap:
the abort often occurs in a later malloc/free, not at the original overwrite
*** stack smashing detected ***: terminated Aborted (core dumped)
what it usually means:
a compiler-inserted canary near a stack frame was modified before function return
likely causes:
out-of-bounds write on a stack array
copying attacker-controlled or unchecked length into a local buffer
overwriting beyon a local struct that contains the canary-adjacent region
*** buffer overflow detected ***: terminated Aborted (core dumped)
*** invalid size (unsorted) ***: terminated Aborted (core dumped)
what it usually means:
libc detected a size or bounds condition it can prove is unsafe (often via compile-time and runtime checks)
likely causes:
passing a length larger than the destination object to memcpy/memmove/strcpy/strncpy/sprintf variants
using strlen on non-terminated memory then copying based on it
common symptom patterns:
crash in unrelated code (for example inside printf, strcmp, or malloc)
nondeterminism: bug disappears under debugger or with different optimization levels
crash shifts when adding logging
likely causes:
small overflows that only damage adjacent heap metadata under certain layouts
use-after-free where the freed region is sometimes reused quickly, sometimes not
uninitialized pointer or length used in memcpy/free, corrupting heap in a data-dependent way
ERROR: AddressSanitizer: heap-use-after-free on address 0x...
ERROR: AddressSanitizer: heap-buffer-overflow on address 0x...
ERROR: AddressSanitizer: stack-use-after-scope on address 0x...
what it usually means:
these are close to the mental model you want: the category is the cause class (use-after-free, overflow, lifetime violation)
the reported stack traces usually include both: the invalid access, and the allocation/free site
"Segmentation fault":
"Bus error":
"Illegal instruction":
"double free or corruption" / "free(): invalid pointer":
"corrupted size" / "invalid next size" / "corrupted top size":
"stack smashing detected":
stack overflow of a local object
If you want this section to stay strictly runtime-oriented, keep the sanitizer subsection optional (for builds that enable it), and emphasize that allocator abort strings are post-hoc consistency checks, not precise explanations of where the memory was first corrupted.