2023-07-10 17:46:57 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
2023-07-10 18:49:22 +00:00
|
|
|
#include <string.h>
|
2023-07-10 17:46:57 +00:00
|
|
|
|
|
|
|
void handler(int)
|
|
|
|
{
|
2023-07-10 18:49:22 +00:00
|
|
|
puts("I caught a segfault!");
|
2023-07-10 17:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
struct sigaction sa;
|
|
|
|
sa.sa_handler = handler;
|
2023-07-10 19:54:04 +00:00
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_flags = SA_RESETHAND;
|
2023-07-10 18:49:22 +00:00
|
|
|
sigaction(SIGSEGV, &sa, NULL);
|
2023-07-10 17:46:57 +00:00
|
|
|
|
2023-07-10 18:49:22 +00:00
|
|
|
#pragma GCC diagnostic ignored "-Wnonnull"
|
|
|
|
char* str = nullptr;
|
|
|
|
memset(str, 0, 2);
|
2023-07-10 17:46:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|