CTU: Avoid FP in else block

This commit is contained in:
Daniel Marjamäki 2018-12-31 08:24:39 +01:00
parent fb6a291370
commit aa4f61acdf
2 changed files with 12 additions and 1 deletions

View File

@ -374,7 +374,7 @@ static bool isUnsafeFunction(const Tokenizer *tokenizer, const Settings *setting
if (!argvar->isPointer())
return false;
for (const Token *tok2 = scope->bodyStart; tok2 != scope->bodyEnd; tok2 = tok2->next()) {
if (Token::simpleMatch(tok2, ") {")) {
if (Token::Match(tok2, ")|else {")) {
tok2 = tok2->linkAt(1);
if (Token::findmatch(tok2->link(), "return|throw", tok2))
return false;

View File

@ -2741,6 +2741,17 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
// else
ctu("void dostuff(int mask, int *p) {\n"
" if (mask == 13) ;\n"
" else *p = 45;\n"
"}\n"
"\n"
"void f() {\n"
" dostuff(0, 0);\n"
"}");
ASSERT_EQUALS("", errout.str());
// ?, &&, ||
ctu("void dostuff(int mask, int *p) {\n"
" x = (mask & 1) ? *p : 0;\n"