Menu

Internal error when checking for unused functions

2021-10-31
2021-11-01
  • Pedro Navarro

    Pedro Navarro - 2021-10-31

    cppcheck 2.6.1 reports error: Internal error. Token::linkAt called with index outside the tokens range. [cppcheckError]. This didn't happen in 2.5.

    I narrowed it down to this:

    void text(std::function<void()> function)
    {
        std::unique_ptr<std::function<void()>> x;
    }
    

    The problem seems to be because the textfunction has a parameter named function which seems to collide with the std::function parameter type passed to std::unique_ptr. If I rename the parameter so it's not called "function" , like void text(std::function<void()> foonction) then cppcheck doesn't report an internal error.

    In checkunusedfunctions.cpp when the next token is < then ftok = ftok->link() is called, but the value of mNextseems to be invalid or null, as the following call to Token::Match prints the error.

            // funcname ( => Assert that the end parentheses isn't followed by {
            if (Token::Match(funcname, "%name% (|<")) {
                const Token *ftok = funcname->next();
                if (ftok->str() == "<")
                    ftok = ftok->link();
                if (Token::Match(ftok->linkAt(1), ") const|throw|{"))
                    funcname = nullptr;
            }
    

    Pedro

     
  • Daniel Marjamäki

    Thanks!
    cppcheck-2.6 crashes for me with a segmentation fault. I do not get any crash in cppcheck HEAD but I wonder if the bug is fixed . Need to investigate a bit why I don't get the crash with head.

     
  • Pedro Navarro

    Pedro Navarro - 2021-11-01

    It used to crash for me, too (I got an Internal error, received signal 11) but it was mostly when I was calling cppcheck with -j20. To debug the problem I isolated the problematic file and that's when I saw the "Internal error: linkat called with index outside the tokens range".

     

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.