From 769b20b4269f589c0a9f097281abb1998a00b8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 24 Jun 2021 17:10:06 +0200 Subject: [PATCH] ValueFlow: Clarify note when impossible value is assigned (#10297) --- lib/tokenlist.cpp | 6 +++--- lib/valueflow.cpp | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 1e3bcc182..ccac6527a 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1637,9 +1637,9 @@ struct OnException { void TokenList::validateAst() const { OnException oe{[&] { - if (mSettings->debugnormal) - mTokensFrontBack.front->printOut(); - }}; + if (mSettings->debugnormal) + mTokensFrontBack.front->printOut(); + }}; // Check for some known issues in AST to avoid crash/hang later on std::set < const Token* > safeAstTokens; // list of "safe" AST tokens without endless recursion for (const Token *tok = mTokensFrontBack.front; tok; tok = tok->next()) { diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index dbf05d82b..e264038a5 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4086,7 +4086,16 @@ static void valueFlowForwardAssign(Token* const tok, values.remove_if(std::mem_fn(&ValueFlow::Value::isTokValue)); if (tok->astParent()) { for (ValueFlow::Value& value : values) { - const std::string info = "Assignment '" + tok->astParent()->expressionString() + "', assigned value is " + value.infoString(); + std::string valueKind; + if (value.valueKind == ValueFlow::Value::ValueKind::Impossible) { + if (value.bound == ValueFlow::Value::Bound::Point) + valueKind = "never "; + else if (value.bound == ValueFlow::Value::Bound::Lower) + valueKind = "less than "; + else if (value.bound == ValueFlow::Value::Bound::Upper) + valueKind = "greater than "; + } + const std::string info = "Assignment '" + tok->astParent()->expressionString() + "', assigned value is " + valueKind + value.infoString(); value.errorPath.emplace_back(tok, info); } }