How to end up with a pointer to 0xCCCCCCCC

后端 未结 4 1409
孤独总比滥情好
孤独总比滥情好 2020-12-11 04:15

The program I\'m working on crashes sometimes trying to read data at the address 0xCCCCCCCC. Google (and StackOverflow) being my friends I saw that it\'s the MS

4条回答
  •  时光说笑
    2020-12-11 04:48

    I do not have MSVC, but this code should produce the problem and compile with no warnings.

    In file f1.c:

    void ignore(int **p) { }
    

    In file f2.c:

    void ignore(int **p);
    int main(int c, char **v)
    {
      int *a;
      ignore(&a);
      return *a;
    }
    

    The call to ignore makes it look like a might be initialized. I doubt the compiler will warn in this case, because of the risk that the warning might be a false positive.

提交回复
热议问题