diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 101c886fe91..01565184736 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -474,6 +474,8 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de tok = tok->next(); tok = tok->next(); + if (!tok) + return tokOld; if (tok->str() == "*") tok = tok->next(); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 75f3ff2abeb..22a727fe719 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -252,6 +252,7 @@ class TestGarbage : public TestFixture { TEST_CASE(garbageCode221); TEST_CASE(garbageCode222); // #10763 TEST_CASE(garbageCode223); // #11639 + TEST_CASE(garbageCode224); TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1 @@ -1719,6 +1720,9 @@ class TestGarbage : public TestFixture { void garbageCode223() { // #11639 ASSERT_THROW(checkCode("struct{}*"), InternalError); // don't crash } + void garbageCode224() { + checkCode("void f(){ auto* b = dynamic_cast