Menu

cppcheck 1.90 printing "vector" and exiting

2019-12-26
2019-12-28
  • Eric Wasylishen

    Eric Wasylishen - 2019-12-26

    I've got a code snippet (reduced from a larger file, and non-compiling) that causes an out of bounds vector access in cppcheck.

    Erics-MacBook-Pro:~ ericwa$ cat test.cpp 
    #include <list>
    #include <string>
    #include <vector>
    
    class AttributableNode  {
    public:
        static AttributeValue selectAttributeValue(const AttributeName& name, const std::vector<AttributableNode*>& attributables);
        const AttributeValue& attribute(const AttributeName& name, const AttributeValue& defaultValue = DefaultAttributeValue) const;            
    };
    
    AttributeValue AttributableNode::selectAttributeValue(const AttributeName& name, const std::vector<AttributableNode*>& attributables) {
        const AttributableNode* attributable = attributables[0];
        const AttributeValue& value = attributable->attribute(name);
        return value;
    }
    
    const AttributeValue& AttributableNode::attribute(const AttributeName& name, const AttributeValue& defaultValue ) const {
        return defaultValue;
    }
    Erics-MacBook-Pro:~ ericwa$ cppcheck --version
    Cppcheck 1.90
    Erics-MacBook-Pro:~ ericwa$ cppcheck ./test.cpp 
    Checking test.cpp ...
    vector
    Erics-MacBook-Pro:~ ericwa$ lldb -- cppcheck ./test.cpp
    (lldb) target create "cppcheck"
    Current executable set to 'cppcheck' (x86_64).
    (lldb) settings set -- target.run-args  "./test.cpp"
    (lldb) b __cxa_throw
    Breakpoint 1: where = libc++abi.dylib`__cxa_throw, address = 0x00000000000022de
    (lldb) run
    Process 4353 launched: '/usr/local/bin/cppcheck' (x86_64)
    Checking test.cpp ...
    Process 4353 stopped
    * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
        frame #0: 0x00007fff6e3c72de libc++abi.dylib`__cxa_throw
    libc++abi.dylib`__cxa_throw:
    ->  0x7fff6e3c72de <+0>: pushq  %rbp
        0x7fff6e3c72df <+1>: movq   %rsp, %rbp
        0x7fff6e3c72e2 <+4>: pushq  %r15
        0x7fff6e3c72e4 <+6>: pushq  %r14
    Target 0: (cppcheck) stopped.
    (lldb) bt
    * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
      * frame #0: 0x00007fff6e3c72de libc++abi.dylib`__cxa_throw
        frame #1: 0x00007fff6e386eb4 libc++.1.dylib`std::__1::__throw_out_of_range(char const*) + 56
        frame #2: 0x00007fff6e3ba3d0 libc++.1.dylib`std::__1::__vector_base_common<true>::__throw_out_of_range() const + 16
        frame #3: 0x0000000100182ddb cppcheck`getLifetimeTokens(Token const*, std::__1::list<std::__1::pair<Token const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<Token const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >, int) + 5320
        frame #4: 0x0000000100182b94 cppcheck`getLifetimeTokens(Token const*, std::__1::list<std::__1::pair<Token const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<Token const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >, int) + 4737
        frame #5: 0x00000001001835fa cppcheck`getLifetimeVariable(Token const*, std::__1::list<std::__1::pair<Token const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<Token const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >&, bool*) + 53
        frame #6: 0x0000000100185cdd cppcheck`ValueFlow::setValues(TokenList*, SymbolDatabase*, ErrorLogger*, Settings const*) + 5030
        frame #7: 0x0000000100145279 cppcheck`Tokenizer::simplifyTokens1(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 523
        frame #8: 0x0000000100098356 cppcheck`CppCheck::checkFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_istream<char, std::__1::char_traits<char> >&) + 11290
        frame #9: 0x00000001000954fb cppcheck`CppCheck::check(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 109
        frame #10: 0x00000001001aeaf9 cppcheck`CppCheckExecutor::check_internal(CppCheck&, int, char const* const*) + 2505
        frame #11: 0x00000001001adf9e cppcheck`CppCheckExecutor::check(int, char const* const*) + 214
        frame #12: 0x00000001001b10df cppcheck`main + 63
        frame #13: 0x00007fff7121c405 libdyld.dylib`start + 1
        frame #14: 0x00007fff7121c405 libdyld.dylib`start + 1
    (lldb) 
    
     
  • Daniel Marjamäki

    Thanks!

    I created this ticket: https://trac.cppcheck.net/ticket/9552

    I've got a code snippet (reduced from a larger file, and non-compiling)

    I think it was reduced well. It might not be compiling but it is not "garbage".

     

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.