Bug hunting; Avoid false warnings for impossible values

This commit is contained in:
Daniel Marjamäki 2020-05-08 17:42:56 +02:00
parent ab8bf81f03
commit d4169f04d5
2 changed files with 15 additions and 0 deletions

View File

@ -2108,6 +2108,8 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer,
return; return;
if (tok->hasKnownIntValue() && tok->getKnownIntValue() != 0) if (tok->hasKnownIntValue() && tok->getKnownIntValue() != 0)
return; return;
if (tok->isImpossibleIntValue(0))
return;
if (value.isUninit()) if (value.isUninit())
return; return;
float f = getKnownFloatValue(tok, 0.0f); float f = getKnownFloatValue(tok, 0.0f);

View File

@ -1032,6 +1032,19 @@ public:
return mImpl->mValues->front().intvalue; return mImpl->mValues->front().intvalue;
} }
bool isImpossibleIntValue(const MathLib::bigint val) const {
if (!mImpl->mValues)
return false;
for (const auto &v: *mImpl->mValues) {
if (v.isIntValue() && v.isImpossible() && v.intvalue == val)
return true;
if (v.isIntValue() && v.bound == ValueFlow::Value::Bound::Lower && v.intvalue > val)
return true;
if (v.isIntValue() && v.bound == ValueFlow::Value::Bound::Upper && v.intvalue < val)
return true;
}
}
const ValueFlow::Value * getValue(const MathLib::bigint val) const { const ValueFlow::Value * getValue(const MathLib::bigint val) const {
if (!mImpl->mValues) if (!mImpl->mValues)
return nullptr; return nullptr;