Assertion failed C/C++ Origin: Application & API Last updated 15 Oct 2026

C/C++: Assertion `x > 0' failed. Aborted (core dumped) — assert() condition was false

An assert() in your code or in a library found its condition false and aborted the program on purpose.

Exact message you may see Assertion failedAssertion `n > 0' failedAssertion failed: (x), function main, file main.cAssertion `__n < this->size()' failed
Seen on: C/C++ Linux GCC Clang

Meaning

assert(cond) documents something that must always be true. The message prints the file, line, function and the expression, so the bug is the broken precondition, not the assert itself. Asserts are removed by -DNDEBUG in release builds, so the same bug may appear as silent corruption there. Hardened standard libraries (-D_GLIBCXX_ASSERTIONS) assert on out-of-range container access too.

Common causes

  • A caller passed a value that violates the function's precondition
  • Index out of range on a container built with _GLIBCXX_ASSERTIONS or in a debug STL
  • A moved-from or uninitialised object was used
  • Side effects hidden inside assert(...) that behave differently with NDEBUG
  • A library's internal consistency check failed after earlier memory corruption

⚡ Quick fix

  1. Read the expression and file:line in the message and trace who supplied the bad value
  2. Run under gdb ./app and use bt after the abort
  3. Never put code with side effects inside assert

Detailed fix by platform

Linux

  1. gdb ./app then run and bt shows the call chain that reached the assert
  2. ulimit -c unlimited to get a core file for post-mortem analysis

GCC / Clang

  1. Build debug with -g -O0; keep asserts on in tests and remove -DNDEBUG from the test configuration

Code examples

Assert and a real check

cpp
#include <cassert>
#include <vector>

int pick(const std::vector<int>& v, std::size_t i) {
    assert(i < v.size() && "index out of range");   // aborts in debug builds
    if (i >= v.size()) return -1;                   // keep a real check for release builds / user input
    return v[i];
}

How to diagnose

  1. Expression — Which condition failed (file:line)?
  2. Caller — Which call supplied the bad value?
  3. Build — Debug or release (NDEBUG)?

🔧 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…call of overloaded is ambiguous — C++: error: call of overloaded 'f(int)' is ambiguous (C/C++)call of overloaded is…cannot 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…pure virtual method called — C++: pure virtual method called — terminate called without an active exception (C/C++)pure virtual method c…runtime error: — C/C++: runtime error: signed integer overflow / null pointer / shift exponent too large (UndefinedBehaviorSanitizer) (C/C++)runtime error:Segmentation fault — C/C++: Segmentation fault (core dumped) — SIGSEGV from a null, dangling or out-of-bounds pointer (C/C++)Segmentation faultterminate called after throwing an instance of — C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check (C/C++)terminate called afte…Assertion…

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.