#include #include #include void handler(int) { puts("I caught a segfault!"); struct sigaction sa; sa.sa_handler = SIG_DFL; sigaction(SIGSEGV, &sa, NULL); } int main() { struct sigaction sa; sa.sa_handler = handler; sigaction(SIGSEGV, &sa, NULL); #pragma GCC diagnostic ignored "-Wnonnull" char* str = nullptr; memset(str, 0, 2); return 0; }