How to enable compiler sanitizers in GCC and Clang for zero-cost runtime bug discovery:
g++ -O1 -g -fsanitize=address,undefined,leak -fno-omit-frame-pointer main.cpp -o mainWhat 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!