From c8010fdf42d7fecea4b23bcd07760b9409fb9377 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 7 Jan 2018 13:11:56 +0100 Subject: [PATCH] Fixed crash on garbage code (#8307) --- lib/valueflow.cpp | 2 +- test/testgarbage.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index b3a4bed8a..736908595 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1073,7 +1073,7 @@ static void valueFlowReverse(TokenList *tokenlist, val.intvalue -= rhsValue; else if (assignToken->str() == "-=") val.intvalue += rhsValue; - else if (assignToken->str() == "*=") + else if (assignToken->str() == "*=" && rhsValue != 0) val.intvalue /= rhsValue; else { if (settings->debugwarnings) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 7ff23bab4..e98ce905d 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -220,6 +220,7 @@ private: TEST_CASE(garbageCode187); TEST_CASE(garbageCode188); TEST_CASE(garbageCode189); // #8317 + TEST_CASE(garbageCode190); // #8307 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageAST); @@ -1442,6 +1443,14 @@ private: checkCode("t&n(){()()[](){()}}$"); } + void garbageCode190() { // #8307 + checkCode("void foo() {\n" + " int i;\n" + " i *= 0;\n" + " !i <;\n" + "}"); + } + void syntaxErrorFirstToken() { ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818 ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858