From 0e8777ec993edb6ff00699065691da3944201e9c Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 31 Jan 2016 10:25:09 +0100 Subject: [PATCH] Fixed crash on garbage code (#7356) --- lib/checkunusedvar.cpp | 2 ++ test/testgarbage.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 0ec4c56b9..4633e6fa9 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -490,6 +490,8 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de tok = tok->next(); tok = tok->tokAt(2); + if (!tok) + return tokOld; if (tok->str() == "&") { addressOf = true; tok = tok->next(); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 2ed5034d5..ec39c46fa 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -222,6 +222,7 @@ private: TEST_CASE(garbageCode171); TEST_CASE(garbageCode172); TEST_CASE(garbageCode173); // #6781 + TEST_CASE(garbageCode174); // #7356 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageAST); @@ -1460,6 +1461,9 @@ private: ASSERT_THROW(checkCode(" template < Types > struct S : >( S < ...Types... > S <) > { ( ) { } } ( ) { return S < void > ( ) }"), InternalError); } + void garbageCode174() { // #7356 + checkCode("{r e() { w*constD = (())D = cast< }}"); + } }; REGISTER_TEST(TestGarbage)