Developer knowledge network · moderated exchange

UnreliableCode қауымдастығы

Әзірлеушілерді зерттеу, кері инженерия және кодтау қауымдастығы

Knowledge indexТірі
4Categories
919Threads
2.8KЖазбалар
Discussion

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

sanitizer_sam
UB Hunter
MEMBER
Өкіл: 119
Қосылу күні: Apr 2021
Хабарламалар: 10
Рахмет: 53
1 ай бұрын · 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
Өкіл: 139
Қосылу күні: Jul 2018
Хабарламалар: 21
Рахмет: 15
1 ай бұрын · 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
Өкіл: 146
Қосылу күні: Aug 2019
Хабарламалар: 33
Рахмет: 31
1 ай бұрын · Jul 1, 2026 2:51 PM
#3

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