Created
February 19, 2019 14:43
-
-
Save antoinealb/2d88b4f79a53dffe230079b2311e7314 to your computer and use it in GitHub Desktop.
How to catch segmentation faults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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