Skip to content

Commit e5f529a

Browse files
Update checkcondition.cpp
1 parent 5a1aa4f commit e5f529a

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

lib/checkcondition.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,11 +1649,20 @@ void CheckCondition::alwaysTrueFalse()
16491649
}
16501650
}
16511651

1652+
static std::string getConditionString(const Token* condition)
1653+
{
1654+
if (Token::simpleMatch(condition, "return"))
1655+
return "Return value";
1656+
if (Token::simpleMatch(condition, "(") && Token::Match(condition->astParent(), "%assign"))
1657+
return "Assigned value";
1658+
return "Condition";
1659+
}
1660+
16521661
void CheckCondition::alwaysTrueFalseError(const Token* tok, const Token* condition, const ValueFlow::Value* value)
16531662
{
16541663
const bool alwaysTrue = value && (value->intvalue != 0 || value->isImpossible());
16551664
const std::string expr = tok ? tok->expressionString() : std::string("x");
1656-
const std::string conditionStr = (Token::simpleMatch(condition, "return") ? "Return value" : "Condition");
1665+
const std::string conditionStr = getConditionString(condition);
16571666
const std::string errmsg = conditionStr + " '" + expr + "' is always " + bool_to_string(alwaysTrue);
16581667
ErrorPath errorPath = getErrorPath(tok, value, errmsg);
16591668
reportError(std::move(errorPath),

0 commit comments

Comments
 (0)