Fixed #7979 (crash (nr 2): CheckFunctions::checkIgnoredReturnValue())

This commit is contained in:
Daniel Marjamäki 2017-04-07 13:18:53 +02:00
parent 392a06a44b
commit 7d8af7bdca
2 changed files with 18 additions and 0 deletions

View File

@ -160,6 +160,18 @@ void CheckFunctions::checkIgnoredReturnValue()
if (Token::Match(tok, "%var%|(|, {"))
tok = tok->linkAt(1);
if (Token::Match(tok->previous(), "%name% (")) {
bool semicolon = false;
for (const Token *tok2 = tok->tokAt(2); tok2 && tok2->str() != ")"; tok2 = tok2->next()) {
if (tok2->str() == ";")
semicolon = true;
else if (Token::Match(tok2, "[({]"))
tok2 = tok2->link();
}
if (semicolon)
tok = tok->link();
}
if (tok->varId() || !Token::Match(tok, "%name% ("))
continue;

View File

@ -912,6 +912,12 @@ private:
" int x({mystrcmp(a,b)});\n"
"}", "test.cpp", &settings2);
ASSERT_EQUALS("", errout.str());
// #7979 - code is not well configured
check("void foo() {\n"
" DEBUG(x(); mystrcmp(a,b););\n"
"}", "test.cpp", &settings2);
ASSERT_EQUALS("", errout.str());
}
};