r/C_Programming • u/Infinite-Can7802 • Jul 26 '26
I compiled the same C code 28 ways and disassembled every binary. assert() and DCHECK provide zero safety at -O2+. I have the disassembly.
I compiled the same C code 28 ways and disassembled every binary. The results are unambiguous:
assert() and DCHECK() provide zero safety in production. At any optimization level above -O0, these checks are stripped. The debug binary at -O2 is identical to the release binary. The check exists in your source code. It does not exist in the binary your users run.
Only explicit if (condition) { return error; } with side effects survives compilation.
I measured 9,712 stripped safety guards across FRRouting, GCC 15.2, and the Linux kernel. Two ASAN-confirmed heap overflows in FRRouting. 27 enterprise firewall CVEs (Cisco, PAN-OS, Fortinet, Juniper) with average CVSS 8.1 — all following this exact pattern. Google confirmed P2/S2 on Android Binder using the same methodology.
Side-by-side disassembly:
c
// SOURCE
void pattern_assert(char *buf, size_t len, size_t idx) {
assert(idx < len);
buf[idx] = 1;
}asm
// -O2 BINARY: assert is GONE
movb $0x1,(%rdi,%rdx,1) // buf[idx] = 1 — NO CHECK
retFull series with reproducible PoCs: https://potatobullet.com/the-naked-compiler-every-safety-net-you-trust-is-already-gone/
The compiler is correct. The standard is correct. The assumption that source-level safety checks survive to the binary is wrong.
Check your binaries, not your source.
TL;DR: assert() and DCHECK() do not survive compilation at -O2+. Use explicit if checks with side effects. Audit your production binaries.I compiled the same C code 28 ways and disassembled every binary. The results are unambiguous:
assert() and DCHECK() provide zero safety in production. At any optimization level above -O0, these checks are stripped. The debug binary at -O2 is identical to the release binary. The check exists in your source code. It does not exist in the binary your users run.
Only explicit if (condition) { return error; } with side effects survives compilation.
I measured 9,712 stripped safety guards
across FRRouting, GCC 15.2, and the Linux kernel. Two ASAN-confirmed
heap overflows in FRRouting. 27 enterprise firewall CVEs (Cisco, PAN-OS,
Fortinet, Juniper) with average CVSS 8.1 — all following this exact
pattern. Google confirmed P2/S2 on Android Binder using the same
methodology.
Side-by-side disassembly:
c
// SOURCE
void pattern_assert(char *buf, size_t len, size_t idx) {
assert(idx < len);
buf[idx] = 1;
}
asm
// -O2 BINARY: assert is GONE
movb $0x1,(%rdi,%rdx,1) // buf[idx] = 1 — NO CHECK
ret
Full series with reproducible PoCs: https://potatobullet.com/the-naked-compiler-every-safety-net-you-trust-is-already-gone/
The compiler is correct. The standard is correct. The assumption that source-level safety checks survive to the binary is wrong.
Check your binaries, not your source.
TL;DR: assert() and DCHECK() do not survive compilation at -O2+. Use explicit if checks with side effects. Audit your production binaries.
•
u/mikeblas Jul 26 '26 edited Jul 26 '26
I don't want to get involved in moderating posts for their truth or not, so I'm leaving this thread open and approved. Yes, it reeks of AI. Yes, the OP doesn't give clear minimal repro cases and it's impossible to reproduce their results. And a couple of other things.
But sort that out in the comments amongst yourselves (and in a civil way). Reasoning out truth it exactly dialogue is for, after all.
8
u/Jonatan83 Jul 26 '26
Your post is unreadable
8
u/aocregacc Jul 26 '26
maybe someone with more LLM experience can answer this: How does one even get to this point? Surely an LLM "knows" how asserts work and that this is not a "50 year industry blindspot". Or is OP just farming engagement?
7
u/skeeto Jul 26 '26
This is 100% AI slop and reads like it, too (1, 2). There is no human here.
2
u/kolorcuk Jul 26 '26
Consider reformating your post, this is uncoickable ale repeated i think.
And what c code?
1
u/sciencekm Jul 26 '26 edited Jul 26 '26
assert() works. In the following example, -O2 was used. -O3 also works. Check your build environment. You probably have NDEBUG defined somewhere.
ubuntu@vpso2:~/tmp$ cat test.c
ubuntu@vpso2:~/tmp$ gcc -Wall -O2 -S test.c
ubuntu@vpso2:~/tmp$ cat test.s
14
u/[deleted] Jul 26 '26
[removed] — view removed comment