Guest User

Untitled

a guest
Jul 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. int c = *((int *)0);
  2.  
  3. printf("%d", c); // to prevent optimizing away the crash
  4.  
  5. #undef HAVE_BUILTIN_TRAP
  6. #ifdef __GNUC__
  7. # define GCC_VERSION (__GNUC__ * 10000
  8. + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
  9. # if GCC_VERSION > 40203
  10. # define HAVE_BUILTIN_TRAP
  11. # endif
  12. #else
  13. # ifdef __has_builtin
  14. # if __has_builtin(__builtin_trap)
  15. # define HAVE_BUILTIN_TRAP
  16. # endif
  17. # endif
  18. #endif
  19.  
  20. #ifdef HAVE_BUILTIN_TRAP
  21. # define crashMe() __builtin_trap()
  22. #else
  23. # include <stdio.h>
  24. # define crashMe() do {
  25. int *volatile iptr = 0;
  26. int i = *iptr;
  27. printf("%d", i);
  28. abort(); } while (0)
  29. #endif
  30.  
  31. // [...]
  32.  
  33. PT_TESTMETHOD(test_expected_crash)
  34. {
  35. PT_Test_expectCrash();
  36.  
  37. // crash intentionally
  38. crashMe();
  39. }
  40.  
  41. *((int *)0) = 0;
  42.  
  43. #include <string.h>
  44.  
  45. void crashme( char *str)
  46. {
  47. char *omg;
  48.  
  49. for(omg=strtok(str, "" ); omg ; omg=strtok(NULL, "") ) {
  50. strcat(omg , "wtf");
  51. }
  52. *omg =0; // always NUL-terminate a NULL string !!!
  53. }
  54.  
  55. int main(void)
  56. {
  57. char buff[20];
  58. // crashme( "WTF" ); // works!
  59. // crashme( NULL ); // works, too
  60. crashme( buff ); // Maybe a bit too slow ...
  61. return 0;
  62. }
  63.  
  64. int main()
  65. {
  66. int *pointer = NULL;
  67. int i = *pointer;
  68. return 0;
  69. }
Add Comment
Please, Sign In to add comment