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)