Menu

false negative: nullptr returned from function

2020-07-28
2020-08-01
  • Christopher Hodde

    Hello

    cppcheck --inconclusive
    does not report a nullptr deref in the following code:

    int* pointer()
    {
    int i = 1;
    return nullptr;
    }

    int main()
    {
    int var = *pointer();
    }

    However, when I delete the line "int i=1;" a finding is reported:
    badcode.cpp:9:20: error: Null pointer dereference: pointer() [nullPointer]
    int var = *pointer();

    Could there be something wrong wih my setup or is this a bug?

    Cppcheck --version
    2.1

     

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.