Menu

Segmentation fault in cppcheck 2.6

Haddayn
2021-10-06
2021-10-18
  • Haddayn

    Haddayn - 2021-10-06

    Hey there.
    Cppcheck 2.6 crashes where cppcheck 2.5 does not
    By removing as much lines as possible, I ended up with this:

    class List
    {
    public:
        struct ListItem
        {
            int value;
        };
    };
    
    int clamp(int i, QVariant v)
    {
        QPair<int, int> range = v.value<QPair<int, int>>();
        return i;
    }
    
    # gdb cppcheck
    (gdb) r --enable=all --std=c++11 --library=qt crash.cpp
    Starting program: /usr/bin/cppcheck --enable=all --std=c++11 --library=qt crash.cpp
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/usr/lib/libthread_db.so.1".
    Checking crash.cpp ...
    crash.cpp:12:27: style: Variable 'range' is assigned a value that is never used. [unreadVariable]
        QPair<int, int> range = v.value<QPair<int, int>>();
                              ^
    
    Program received signal SIGSEGV, Segmentation fault.
    0x000055555583562b in Token::linkAt(int) const ()
    (gdb) bt
    #0  0x000055555583562b in Token::linkAt(int) const ()
    #1  0x000055555571737d in CheckUnusedFunctions::parseTokens(Tokenizer const&, char const*, Settings const*) ()
    #2  0x000055555571871c in CheckUnusedFunctions::getFileInfo(Tokenizer const*, Settings const*) const ()
    #3  0x00005555557406ed in CppCheck::checkNormalTokens(Tokenizer const&) ()
    #4  0x000055555574b859 in CppCheck::checkFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::istream&) ()
    #5  0x000055555574cd05 in CppCheck::check(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
    #6  0x000055555561080b in CppCheckExecutor::check_internal(CppCheck&, int, char const* const*) ()
    #7  0x0000555555610cb1 in CppCheckExecutor::check(int, char const* const*) ()
    #8  0x00005555555f9c70 in main ()
    (gdb) 
    
     

    Last edit: Haddayn 2021-10-06
  • Haddayn

    Haddayn - 2021-10-06

    Managed to trim it a little bit more:

    struct ListItem
    {
        int value;
    };
    
    void clamp()
    {
        auto range = v.value<QPair<int, int>>();
    }
    

    Reduced parameters to the following:

    cppcheck --enable=unusedFunction crash.cpp
    
     

    Last edit: Haddayn 2021-10-06
  • Haddayn

    Haddayn - 2021-10-16

    Could someone please file a ticket? Or is there already a ticket for this?

     
  • Georgiy Komarov

    Georgiy Komarov - 2021-10-16

    I can't confirm crash for this case, but there is an internal error. Here is output on the both examples for cppcheck from main branch (commit 27d7609d):

    ~/D/cppcheck  main   ./cppcheck --enable=unusedFunction test.cpp
    Checking test.cpp ...
    test.cpp:0:0: error: Internal error. Token::linkAt called with index outside the tokens range. [cppcheckError]
    
    ^
    test.cpp:6:0: style: The function 'clamp' is never used. [unusedFunction]
    
    ^
    ~/D/cppcheck  main ./cppcheck --enable=all --std=c++11 --library=qt test.cpp
    Checking test.cpp ...
    test.cpp:12:27: style: Variable 'range' is assigned a value that is never used. [unreadVariable]
        QPair<int, int> range = v.value<QPair<int, int>>();
                              ^
    test.cpp:0:0: error: Internal error. Token::linkAt called with index outside the tokens range. [cppcheckError]
    
    ^
    test.cpp:10:0: style: The function 'clamp' is never used. [unusedFunction]
    
     
  • CHR

    CHR - 2021-10-18
     

Log in to post a comment.