Menu

null pointer dereference

arseniy
2020-03-12
2020-03-16
  • arseniy

    arseniy - 2020-03-12

    Hello, here is small example:

    int main(void)
    {
    int * p = malloc(sizeof(int));

    *p = 1;
    return 0
    

    }

    My question is: why cppcheck warns only about memory leak? There is also potential null pointer dereference.

    Thank you

     

    Last edit: arseniy 2020-03-12
    • Markus Elfring

      Markus Elfring - 2020-03-14

      Will return value ignorance matter any more in such situations?

       
      • arseniy

        arseniy - 2020-03-14

        Sorry, what do You mean? Yes this is obvious UB, but why cppcheck ignores it?

         
        • Markus Elfring

          Markus Elfring - 2020-03-14

          I suggest to take another look at improving source code analysis capabilities.
          Would you like to help any further with corresponding software development resources?

           
  • Daniel Marjamäki

    We normally only warn when we can prove there are bugs.

    Unless there is oom malloc will not return NULL. In that small program it's very unlikely there is oom. In larger programs it is hard to prove.

    The plan is there will be more noisy analysis in cppcheck 2.x and when that will be used to detect null pointer dereference I believe we would warn for that code. The plan is that next release will be 2.0 but that will not have a null pointer check. Null pointer checking will be added later (no idea when)...

     

    Last edit: Daniel Marjamäki 2020-03-14
    • arseniy

      arseniy - 2020-03-16

      ok, thanks :)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.