From 26a8435d764a6bd210b4d92c9516e03f7d180fed Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Thu, 4 Oct 2018 23:00:24 -0500 Subject: [PATCH] Use knownConditionTrueFalse when is duplicate expression is true or false (#1410) --- lib/checkother.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 937bc295b..d7af3698a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2058,7 +2058,9 @@ void CheckOther::duplicateExpressionError(const Token *tok1, const Token *tok2, const std::string& op = opTok ? opTok->str() : "&&"; std::string msg = "Same expression on both sides of \'" + op + "\'"; + std::string id = "duplicateExpression"; if (expr1 != expr2) { + id = "knownConditionTrueFalse"; std::string exprMsg = "The expression \'" + expr1 + " " + op + " " + expr2 + "\' is always "; if (Token::Match(opTok, "==|>=|<=")) msg = exprMsg + "true"; @@ -2068,7 +2070,7 @@ void CheckOther::duplicateExpressionError(const Token *tok1, const Token *tok2, msg += " because '" + expr1 + "' and '" + expr2 + "' represent the same value"; } - reportError(errors, Severity::style, "duplicateExpression", msg + ".\n" + reportError(errors, Severity::style, id.c_str(), msg + ".\n" "Finding the same expression on both sides of an operator is suspicious and might " "indicate a cut and paste or logic error. Please examine this code carefully to " "determine if it is correct.", CWE398, false);