C/C++: Bus error (core dumped) — SIGBUS from misaligned access or a bad memory-mapped file
The CPU or OS rejected a memory access that is not a plain invalid address: misaligned data, or touching a memory-mapped file page that no longer exists.
Bus error (core dumped)Bus error: 10EXC_BAD_ACCESS (code=EXC_I386_GPFLT)Unaligned access Meaning
SIGBUS differs from SIGSEGV: the address may be valid but the access is not allowed. On ARM and SPARC, misaligned reads of int or double raise it; on x86 and macOS it more often comes from mmap: the file was truncated, the disk filled up, or the file lives on a removed network share. Writing to a string literal on some platforms also produces it.
Common causes
mmaped file truncated or deleted while the program reads it- Disk full or quota exceeded when writing to an mmap'ed or sparse file
- Misaligned pointer cast (
*(int*)(buf + 1)) on strict-alignment CPUs - Writing into a string literal or read-only mapping
- Stack alignment problems in hand-written assembly
⚡ Quick fix
- Check file size before and while using
mmapand handleSIGBUScarefully - Use
memcpyto read unaligned values instead of casting the pointer - Never modify string literals — copy them to a
char[]
Detailed fix by platform
Linux
- Verify space:
df -handls -lthe mapped file gdb ./app→btshows the access that faulted
macOS
- Bus error: 10 often means a write to read-only memory or a truncated mapped file
Code examples
Safe unaligned read
#include <cstdint>
#include <cstring>
uint32_t read_u32(const unsigned char* p) {
uint32_t v;
std::memcpy(&v, p, sizeof v); // safe for any alignment
return v; // *(uint32_t*)p could raise SIGBUS on strict CPUs
}How to diagnose
- Mapping — Is a mmap'ed file involved?
- Disk — Is the disk full?
- Alignment — Any pointer cast to a wider type?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- 0xC0000005 The application was unable to start correctly (0xc0000005) / Exception code 0xc0000005 access violation
- AddressSanitizer: heap-buffer-overflow C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N
- AddressSanitizer: heap-use-after-free C/C++: ==ERROR: AddressSanitizer: heap-use-after-free on address — memory used after delete/free
Most viewed in C/C++
- terminate called after throwing an instance of C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check
- undefined reference to C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status
- expected ';' before C/C++: error: expected ';' before 'x' — missing semicolon
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026