From d4169f04d58e3985b05f77d4afcf80e100ab6bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 8 May 2020 17:42:56 +0200 Subject: [PATCH] Bug hunting; Avoid false warnings for impossible values --- lib/exprengine.cpp | 2 ++ lib/token.h | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index 8ec3a8ab9..95bdd8209 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -2108,6 +2108,8 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer, return; if (tok->hasKnownIntValue() && tok->getKnownIntValue() != 0) return; + if (tok->isImpossibleIntValue(0)) + return; if (value.isUninit()) return; float f = getKnownFloatValue(tok, 0.0f); diff --git a/lib/token.h b/lib/token.h index cb571093f..0ad9f3672 100644 --- a/lib/token.h +++ b/lib/token.h @@ -1032,6 +1032,19 @@ public: 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 { if (!mImpl->mValues) return nullptr;