Menu

Cppcheck 2.18.3 False positive nullPointerRedundantCheck

2025-10-07
2025-10-08
  • Félix-Antoine Constantin

    Using cppcheck 2.18, the following code snippet will raise nullPointerRedundantCheck even if it shouldn't.

    #include <stdlib.h>
    
    [[noreturn]] void bar(const char *format, ...)
        __attribute__((format(printf, 1, 2)));
    
    
    int foo(char* location)
    {
        if (location == nullptr)
        {
            bar("");
        }
        return strtol(location, nullptr, 10);
    }
    

    cppcheck --enable=warning test.cpp

    test.cpp:13:16: warning: Either the condition 'location==nullptr' is redundant or there is possible null pointer dereference: location. [nullPointerRedundantCheck]
     return strtol(location, nullptr, 10);
                   ^
    test.cpp:9:15: note: Assuming that condition 'location==nullptr' is not redundant
     if (location == nullptr)
                  ^
    test.cpp:13:16: note: Null pointer dereference
     return strtol(location, nullptr, 10);
                   ^
    

    This seems related to the following issue that should have been fixed in 2023: https://sourceforge.net/p/cppcheck/discussion/general/thread/02fab2bec8/

    Please let me know if any information is missing!

     
  • CHR

    CHR - 2025-10-08

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14181

     

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.