Developer knowledge network · moderated exchange

Zajednica UnreliableCode

Zajednica za istraživanje, obrnuti inženjering i programiranje programera

Knowledge indexŽivjeti
4Categories
919Threads
2.8KPostovi
Discussion

Detecting subtle Undefined Behavior with AddressSanitizer (ASan) and UndefinedBehaviorSanitizer (UBSan) [StackOverflow Architecture Guide]

sanitizer_sam
UB Hunter
MEMBER
Rep: 119
Datum pridruživanja: Apr 2021
Postovi: 10
Hvala: 53
prije 1 mjeseci · Jun 30, 2026 11:44 PM
#1

How to enable compiler sanitizers in GCC and Clang for zero-cost runtime bug discovery:

BASH
g++ -O1 -g -fsanitize=address,undefined,leak -fno-omit-frame-pointer main.cpp -o main

What Sanitizers Catch Instantly:

  • Out-of-bounds heap / stack / global array access
  • Use-After-Free and Double-Free errors
  • Signed integer overflow (UB in C/C++)
  • Null pointer dereferences and misaligned pointer casts
  • Memory leaks upon process exit with precise file and line numbers!
llvm_compiler_dev
LLVM & Clang Hacker
MEMBER
Rep: 139
Datum pridruživanja: Jul 2018
Postovi: 21
Hvala: 15
prije 1 mjeseci · Jul 1, 2026 3:57 AM
#2

AddressSanitizer replaced 90% of our Valgrind usage. It runs at only ~2x slowdown compared to Valgrind's 20x slowdown, making it feasible to run during full test suites.

profiler_pat
Performance Hunter
MEMBER
Rep: 146
Datum pridruživanja: Aug 2019
Postovi: 33
Hvala: 31
prije 1 mjeseci · Jul 1, 2026 2:51 PM
#3

Running UBSan on legacy codebases always exposes unexpected signed overflows in integer math routines.