From 1fccfd50ebcdbbf788930e015fded7f5bc4c2bab Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 12 Oct 2013 10:50:59 +0200 Subject: [PATCH] Fixed #5080 ((error) Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers) --- lib/checknullpointer.cpp | 4 ++++ test/testnullpointer.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 7a95d9000..f3525b1ca 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -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; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 7e65c8411..312deb0d5 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -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)