Created
November 23, 2017 06:46
-
-
Save icecoobe/48e0d2c10aaed8f5bfa25cc541b3426c to your computer and use it in GitHub Desktop.
SEH in C
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 <stdio.h> | |
#include <stdlib.h> | |
#include <setjmp.h> | |
#include <assert.h> | |
static void test(void); | |
static void test2(void); | |
jmp_buf exception_handled; | |
int main(void) | |
{ | |
int ret = 0; | |
if (ret = setjmp(exception_handled)) | |
{ | |
fprintf(stderr, "Exception occurred! code=0x%04X\n", ret); | |
return -1; | |
} | |
test(); | |
printf("Program terminated!\n"); | |
return 0; | |
} | |
void test(void) | |
{ | |
printf("In function test\n"); | |
test2(); | |
if (exception_handled) | |
longjmp(exception_handled, 1); | |
test2(); | |
assert(0); | |
} | |
void test2(void) | |
{ | |
printf("In function test-2\n"); | |
if (exception_handled) | |
longjmp(exception_handled, -2); | |
assert(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment