Runtime Sanitizers (ASan & UBSan)
🟡 Intermediate
📖 Definition
AddressSanitizer (-fsanitize=address) instruments binary code to catch heap/stack buffer overflows, use-after-free, and memory leaks at runtime. UndefinedBehaviorSanitizer (-fsanitize=undefined) catches null pointer dereferences and signed integer overflows.
💡 Code Example
# Compile with ASan and UBSan flags
g++ -fsanitize=address,undefined -g -std=c++17 main.cpp -o main_sanitized
./main_sanitized