Fixed crash on garbage code (#8307)

This commit is contained in:
PKEuS 2018-01-07 13:11:56 +01:00
parent 817f66d74d
commit c8010fdf42
2 changed files with 10 additions and 1 deletions

View File

@ -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)

View File

@ -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