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