CTU: Avoid FP in code protected by &&,||,?

This commit is contained in:
Daniel Marjamäki 2018-12-31 08:16:21 +01:00
parent a520a41e64
commit fb6a291370
2 changed files with 14 additions and 0 deletions

View File

@ -381,6 +381,10 @@ static bool isUnsafeFunction(const Tokenizer *tokenizer, const Settings *setting
if (isVariableChanged(tok2->link(), tok2, argvar->declarationId(), false, settings, tokenizer->isCPP()))
return false;
}
if (Token::Match(tok2, "%oror%|&&|?")) {
tok2 = tok2->findExpressionStartEndTokens().second;
continue;
}
if (tok2->variable() != argvar)
continue;
if (!isUnsafeUsage(check, tok2))

View File

@ -2740,6 +2740,16 @@ private:
" dostuff(a, 0);\n"
"}");
ASSERT_EQUALS("", errout.str());
// ?, &&, ||
ctu("void dostuff(int mask, int *p) {\n"
" x = (mask & 1) ? *p : 0;\n"
"}\n"
"\n"
"void f() {\n"
" dostuff(0, 0);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};