Skip to content

Instantly share code, notes, and snippets.

@alex-eg
Created June 20, 2016 15:26
Show Gist options
  • Select an option

  • Save alex-eg/98548eccaa54b4297b01511ea0a15e03 to your computer and use it in GitHub Desktop.

Select an option

Save alex-eg/98548eccaa54b4297b01511ea0a15e03 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
int i = 0;
jmp_buf jump_buffer;
void sigsegv_handler(int signum) {
printf(" Ignoring SIGSEGV is a bad idea\n");
longjmp(jump_buffer, 1);
}
int main(void) {
signal(SIGSEGV, sigsegv_handler); // huh
int *p = &i;
for(; i < 1000; i ++) {
if (sigsetjmp(jump_buffer, 1) == 0) {
printf("%d:", i);
printf(" %lp", i + p);
printf(" %d\n", *(i + p));
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment