Skip to content

Commit 1fccfd5

Browse files
IOBYTEdanmar
authored andcommitted
Fixed cppcheck-opensource#5080 ((error) Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers)
1 parent 783bb6e commit 1fccfd5

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/checknullpointer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,10 @@ void CheckNullPointer::nullPointerLinkedList()
520520
// Variable id for dereferenced variable
521521
const unsigned int varid(tok2->varId());
522522

523+
// We don't support variables without a varid
524+
if (varid == 0)
525+
continue;
526+
523527
if (Token::Match(tok2->tokAt(-2), "%varid% ?", varid))
524528
continue;
525529

test/testnullpointer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class TestNullPointer : public TestFixture {
7575
TEST_CASE(functioncalllibrary); // use Library to parse function call
7676
TEST_CASE(crash1);
7777
TEST_CASE(functioncallDefaultArguments);
78+
TEST_CASE(nullpointer_internal_error); // #5080
7879
}
7980

8081
void check(const char code[], bool inconclusive = false, const char filename[] = "test.cpp", bool verify=true) {
@@ -2320,6 +2321,17 @@ class TestNullPointer : public TestFixture {
23202321
" return if\n"
23212322
"}");
23222323
}
2324+
2325+
void nullpointer_internal_error() { // ticket #5080
2326+
check("struct A { unsigned int size; };\n"
2327+
"struct B { struct A *a; };\n"
2328+
"void f(struct B *b) {\n"
2329+
" unsigned int j;\n"
2330+
" for (j = 0; j < b[0].a->size; ++j) {\n"
2331+
" }\n"
2332+
"}\n");
2333+
ASSERT_EQUALS("", errout.str());
2334+
}
23232335
};
23242336

23252337
REGISTER_TEST(TestNullPointer)

0 commit comments

Comments
 (0)