Menu

nullPointerRedundantCheck false positive with try-catch

Valentin
2022-12-06
2022-12-07
  • Valentin

    Valentin - 2022-12-06

    The following code triggers warning:
    warning GDE5FDDA5: Either the condition '!a' is redundant or there is possible null pointer dereference: a. [nullPointerRedundantCheck]

    The code is simplified. The issue also reproduces when "a" is a class member and the function is a class method.

    int main()
    {
        static int* a = nullptr;
    
        if (!a)
        {
            try
            {
                a = new int(10);
            }
            catch (...)
            {
                return 1;
            }
        }
    
        std::cout << *a << std::endl;
    
        return 0;
    }
    
     
  • CHR

    CHR - 2022-12-07

    Thanks for reporting, the issue is covered by this ticket: https://trac.cppcheck.net/ticket/10572

     

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.