Use knownConditionTrueFalse when is duplicate expression is true or false (#1410)

This commit is contained in:
Paul Fultz II 2018-10-04 23:00:24 -05:00 committed by Daniel Marjamäki
parent e170a45230
commit 26a8435d76
1 changed files with 3 additions and 1 deletions

View File

@ -2058,7 +2058,9 @@ void CheckOther::duplicateExpressionError(const Token *tok1, const Token *tok2,
const std::string& op = opTok ? opTok->str() : "&&"; const std::string& op = opTok ? opTok->str() : "&&";
std::string msg = "Same expression on both sides of \'" + op + "\'"; std::string msg = "Same expression on both sides of \'" + op + "\'";
std::string id = "duplicateExpression";
if (expr1 != expr2) { if (expr1 != expr2) {
id = "knownConditionTrueFalse";
std::string exprMsg = "The expression \'" + expr1 + " " + op + " " + expr2 + "\' is always "; std::string exprMsg = "The expression \'" + expr1 + " " + op + " " + expr2 + "\' is always ";
if (Token::Match(opTok, "==|>=|<=")) if (Token::Match(opTok, "==|>=|<="))
msg = exprMsg + "true"; 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"; 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 " "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 " "indicate a cut and paste or logic error. Please examine this code carefully to "
"determine if it is correct.", CWE398, false); "determine if it is correct.", CWE398, false);