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

C/C++: runtime error: signed integer overflow / null pointer / shift exponent too large (UndefinedBehaviorSanitizer)

UBSan detected code that triggers undefined behaviour (overflow, null dereference, out-of-bounds index, bad shift, misaligned access) — the program may appear to work and still be wrong.

Exact message you may see runtime error: signed integer overflowruntime error: member access within null pointerruntime error: shift exponentruntime error: index out of boundsruntime error: load of misaligned address
Seen on: C/C++ GCC Clang

Meaning

Undefined behaviour lets the optimiser assume it never happens, so bugs surface only at -O2, on other compilers, or after a compiler upgrade. UBSan reports file:line:col: runtime error: <what>. Fix each report rather than silencing it.

Common causes

  • Signed integer overflow (INT_MAX + 1)
  • Null pointer dereference or member access through null
  • Array index out of bounds or shift by a negative or too large count
  • Misaligned access, invalid enum or bool value
  • Division by zero or INT_MIN / -1

⚡ Quick fix

  1. Compile with -fsanitize=undefined and run your tests
  2. Use wider or unsigned types, or check ranges before arithmetic
  3. Add bounds and null checks

Detailed fix by platform

GCC / Clang

  1. g++ -g -fsanitize=undefined -fno-sanitize-recover=all main.cpp stops at the first report
  2. Combine with address: -fsanitize=address,undefined

CMake

  1. target_compile_options(app PRIVATE -fsanitize=undefined) and target_link_options(app PRIVATE -fsanitize=undefined)

Code examples

Checked arithmetic

cpp
#include <climits>
#include <iostream>

int add_checked(int a, int b) {
    if ((b > 0 && a > INT_MAX - b) || (b < 0 && a < INT_MIN - b)) {
        throw std::overflow_error("int overflow");       // instead of undefined behaviour
    }
    return a + b;
}

int main() { std::cout << add_checked(INT_MAX, 1) << "\n"; }

How to diagnose

  1. Message — Which kind of undefined behaviour?
  2. Line — file:line:col from the report?
  3. Inputs — Which values trigger it?

🔧 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):

AddressSanitizer: 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…Assertion failed — C/C++: Assertion `x > 0' failed. Aborted (core dumped) — assert() condition was false (C/C++)Assertion failedcannot declare variable to be of abstract type — C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions) (C/C++)cannot declare variab…control reaches end of non-void function — C/C++: warning: control reaches end of non-void function [-Wreturn-type] (C/C++)control reaches end o…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…narrowing conversion — C++: error: narrowing conversion of 'x' from 'int' to 'char' inside { } [-Wnarrowing] (C/C++)narrowing conversionruntime e…

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.