From c2d7824130efbbc98d14c86be066431a1a6b3049 Mon Sep 17 00:00:00 2001 From: Richard Quirk Date: Sat, 29 Oct 2011 11:52:19 +0200 Subject: [PATCH] Move string comparison out of the report function --- lib/checkother.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index cc98c1377..2dc727874 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2306,7 +2306,10 @@ void CheckOther::checkAlwaysTrueOrFalseStringCompare() while (tok && (tok = Token::findmatch(tok, pattern3)) != NULL) { const Token *var1 = tok->tokAt(2); const Token *var2 = tok->tokAt(4); - alwaysTrueStringVariableCompareError(tok, var1->str(), var2->str()); + const std::string &str1 = var1->str(); + const std::string &str2 = var2->str(); + if (str1 == str2) + alwaysTrueStringVariableCompareError(tok, str1, str2); tok = tok->tokAt(5); } } @@ -2333,12 +2336,10 @@ void CheckOther::alwaysTrueFalseStringCompareError(const Token *tok, const std:: void CheckOther::alwaysTrueStringVariableCompareError(const Token *tok, const std::string& str1, const std::string& str2) { - if (str1 == str2) { - reportError(tok, Severity::warning, "stringCompare", - "Comparison of identical string variables.\n" - "The compared strings, '" + str1 + "' and '" + str2 + "', are identical. " - "This could be a logic bug."); - } + reportError(tok, Severity::warning, "stringCompare", + "Comparison of identical string variables.\n" + "The compared strings, '" + str1 + "' and '" + str2 + "', are identical. " + "This could be a logic bug."); } //-----------------------------------------------------------------------------