Verification; avoid false positive for known float value

This commit is contained in:
Daniel Marjamäki 2020-01-01 08:33:27 +01:00
parent d4ec8075a4
commit 443e8cfbcf
1 changed files with 12 additions and 0 deletions

View File

@ -1755,6 +1755,15 @@ void ExprEngine::executeFunction(const Scope *functionScope, const Tokenizer *to
} }
} }
static float getKnownFloatValue(const Token *tok, float def)
{
for (const auto &value: tok->values()) {
if (value.isKnown() && value.valueType == ValueFlow::Value::ValueType::FLOAT)
return value.floatValue;
}
return def;
}
void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer, const Settings *settings) void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer, const Settings *settings)
{ {
std::function<void(const Token *, const ExprEngine::Value &, ExprEngine::DataBase *)> divByZero = [=](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) { std::function<void(const Token *, const ExprEngine::Value &, ExprEngine::DataBase *)> divByZero = [=](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) {
@ -1762,6 +1771,9 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer,
return; return;
if (tok->hasKnownIntValue() && tok->getKnownIntValue() != 0) if (tok->hasKnownIntValue() && tok->getKnownIntValue() != 0)
return; return;
float f = getKnownFloatValue(tok, 0.0f);
if (f > 0.0f || f < 0.0f)
return;
if (tok->astParent()->astOperand2() == tok && value.isEqual(dataBase, 0)) { if (tok->astParent()->astOperand2() == tok && value.isEqual(dataBase, 0)) {
dataBase->addError(tok->linenr()); dataBase->addError(tok->linenr());
std::list<const Token*> callstack{tok->astParent()}; std::list<const Token*> callstack{tok->astParent()};