Fixed #5080 ((error) Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers)
This commit is contained in:
parent
783bb6eb0b
commit
1fccfd50eb
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue