Why can't I cause a seg fault?

前端 未结 10 1699
名媛妹妹
名媛妹妹 2020-12-31 00:24

OK for whatever reason I\'m having trouble causing a seg fault. I want to produce one so that I can use gdb to see how to debug one. I have tried both examples

相关标签:
10条回答
  • 2020-12-31 01:17
    int *hello = NULL;
    printf(*hello);
    

    or you can define a struct (say HelloWorld struct)

    HelloWorld *myWorld = NULL;
    myWorld->world = "hello";
    
    0 讨论(0)
  • 2020-12-31 01:17

    Lots of ways to generate a segfault.

    Like dereferencing a bad pointer:

    char *s = (char *)0xDEADBEEF;
    *s = 'a';
    
    0 讨论(0)
  • 2020-12-31 01:20

    My one line flavor:

    *(char *)0 = 0;
    
    0 讨论(0)
  • 2020-12-31 01:21

    If you try to concatenate two constants... you'll get one... at least is a simple way...

    strcat("a", "b");

    =)

    0 讨论(0)
提交回复
热议问题