Compile with -fsanitize=address and the program stops at the first bad access with a report naming the error type and the line. It slows the program down and is meant for tests and CI, not production. Fuzzing is often run with it.
AddressSanitizer
A compiler-inserted runtime checker (ASan) that reports out-of-bounds access, use-after-free and double free.