Skip to content

Instantly share code, notes, and snippets.

@antoinealb
Created February 19, 2019 14:43
Show Gist options
  • Save antoinealb/2d88b4f79a53dffe230079b2311e7314 to your computer and use it in GitHub Desktop.
Save antoinealb/2d88b4f79a53dffe230079b2311e7314 to your computer and use it in GitHub Desktop.
How to catch segmentation faults
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
void myhandler(int signum)
{
printf("got signal %d\n", signum);
exit(1);
}
int main(void)
{
signal(SIGSEGV, myhandler);
int *a = NULL;
*a = 42;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment