Bus error C/C++ Origin: Application & API Last updated 15 Oct 2026

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.

Exact message you may see Bus error (core dumped)Bus error: 10EXC_BAD_ACCESS (code=EXC_I386_GPFLT)Unaligned access
Seen on: C/C++ Linux macOS

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

  1. Check file size before and while using mmap and handle SIGBUS carefully
  2. Use memcpy to read unaligned values instead of casting the pointer
  3. Never modify string literals — copy them to a char[]

Detailed fix by platform

Linux

  1. Verify space: df -h and ls -l the mapped file
  2. gdb ./app → bt shows the access that faulted

macOS

  1. Bus error: 10 often means a write to read-only memory or a truncated mapped file

Code examples

Safe unaligned read

cpp
#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

  1. Mapping — Is a mmap'ed file involved?
  2. Disk — Is the disk full?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

0xC0000005 — The application was unable to start correctly (0xc0000005) / Exception code 0xc0000005 access violation (Windows)0xC0000005AddressSanitizer: heap-buffer-overflow — C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N (C/C++)AddressSanitizer: hea…AddressSanitizer: heap-use-after-free — C/C++: ==ERROR: AddressSanitizer: heap-use-after-free on address — memory used after delete/free (C/C++)AddressSanitizer: hea…Cannot allocate memory — fork: Cannot allocate memory / ENOMEM (Linux)Cannot allocate memorydouble free or corruption — C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped) (C/C++)double free or corrup…Floating point exception — C/C++: Floating point exception (core dumped) — SIGFPE, usually integer division by zero (C/C++)Floating point except…LeakSanitizer: detected memory leaks — C/C++: ==ERROR: LeakSanitizer: detected memory leaks — Direct leak of N byte(s) (C/C++)LeakSanitizer: detect…MEMORY_MANAGEMENT — Blue Screen: MEMORY_MANAGEMENT (Stop code 0x0000001A) (Windows)MEMORY_MANAGEMENTBus error

Explore the map of this error Full error map →

🧠 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.