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