Skip to content

Instantly share code, notes, and snippets.

@dariost
Created March 21, 2017 08:55
Show Gist options
  • Save dariost/deab862348d46028662e1dad969ce155 to your computer and use it in GitHub Desktop.
Save dariost/deab862348d46028662e1dad969ce155 to your computer and use it in GitHub Desktop.
For implemented with SIGSEGV handling
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
jmp_buf jump_buffer;
int count = 0;
void handler(int p)
{
(void)p;
siglongjmp(jump_buffer, count++);
}
int main(int argc, char* argv[])
{
(void)argc;
(void)argv;
signal(SIGSEGV, handler);
int* lel = NULL;
if(!sigsetjmp(jump_buffer, 1))
printf("%d\n", *lel);
printf("%d\n", count - 1);
if(count == 10)
return 0;
printf("%d\n", *lel);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment