Fixed #5080 ((error) Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers)

This commit is contained in:
Robert Reif 2013-10-12 10:50:59 +02:00 committed by Daniel Marjamäki
parent 783bb6eb0b
commit 1fccfd50eb
2 changed files with 16 additions and 0 deletions

View File

@ -520,6 +520,10 @@ void CheckNullPointer::nullPointerLinkedList()
// Variable id for dereferenced variable
const unsigned int varid(tok2->varId());
// We don't support variables without a varid
if (varid == 0)
continue;
if (Token::Match(tok2->tokAt(-2), "%varid% ?", varid))
continue;

View File

@ -75,6 +75,7 @@ private:
TEST_CASE(functioncalllibrary); // use Library to parse function call
TEST_CASE(crash1);
TEST_CASE(functioncallDefaultArguments);
TEST_CASE(nullpointer_internal_error); // #5080
}
void check(const char code[], bool inconclusive = false, const char filename[] = "test.cpp", bool verify=true) {
@ -2320,6 +2321,17 @@ private:
" return if\n"
"}");
}
void nullpointer_internal_error() { // ticket #5080
check("struct A { unsigned int size; };\n"
"struct B { struct A *a; };\n"
"void f(struct B *b) {\n"
" unsigned int j;\n"
" for (j = 0; j < b[0].a->size; ++j) {\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestNullPointer)