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.