Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int c = *((int *)0);
- printf("%d", c); // to prevent optimizing away the crash
- #undef HAVE_BUILTIN_TRAP
- #ifdef __GNUC__
- # define GCC_VERSION (__GNUC__ * 10000
- + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
- # if GCC_VERSION > 40203
- # define HAVE_BUILTIN_TRAP
- # endif
- #else
- # ifdef __has_builtin
- # if __has_builtin(__builtin_trap)
- # define HAVE_BUILTIN_TRAP
- # endif
- # endif
- #endif
- #ifdef HAVE_BUILTIN_TRAP
- # define crashMe() __builtin_trap()
- #else
- # include <stdio.h>
- # define crashMe() do {
- int *volatile iptr = 0;
- int i = *iptr;
- printf("%d", i);
- abort(); } while (0)
- #endif
- // [...]
- PT_TESTMETHOD(test_expected_crash)
- {
- PT_Test_expectCrash();
- // crash intentionally
- crashMe();
- }
- *((int *)0) = 0;
- #include <string.h>
- void crashme( char *str)
- {
- char *omg;
- for(omg=strtok(str, "" ); omg ; omg=strtok(NULL, "") ) {
- strcat(omg , "wtf");
- }
- *omg =0; // always NUL-terminate a NULL string !!!
- }
- int main(void)
- {
- char buff[20];
- // crashme( "WTF" ); // works!
- // crashme( NULL ); // works, too
- crashme( buff ); // Maybe a bit too slow ...
- return 0;
- }
- int main()
- {
- int *pointer = NULL;
- int i = *pointer;
- return 0;
- }
Add Comment
Please, Sign In to add comment