Developer knowledge network · moderated exchange

UnreliableCode-Community

Community für Entwicklerforschung, Reverse Engineering und Codierung

Knowledge indexLive
4Categories
919Threads
2.8KBeiträge
Discussion

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

sanitizer_sam
UB Hunter
MEMBER
Vertreter: 119
Beitrittsdatum: Apr 2021
Beiträge: 10
Danke: 53
Vor 1 Monaten · 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
Vertreter: 139
Beitrittsdatum: Jul 2018
Beiträge: 21
Danke: 15
Vor 1 Monaten · 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
Vertreter: 146
Beitrittsdatum: Aug 2019
Beiträge: 33
Danke: 31
Vor 1 Monaten · Jul 1, 2026 2:51 PM
#3

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