| 134 | } |
| 135 | |
| 136 | void CheckStringImpl::alwaysTrueFalseStringCompareError(const Token *tok, const std::string& str1, const std::string& str2) |
| 137 | { |
| 138 | constexpr std::size_t stringLen = 10; |
| 139 | const std::string string1 = (str1.size() < stringLen) ? str1 : (str1.substr(0, stringLen-2) + ".."); |
| 140 | const std::string string2 = (str2.size() < stringLen) ? str2 : (str2.substr(0, stringLen-2) + ".."); |
| 141 | |
| 142 | reportError(tok, Severity::warning, "staticStringCompare", |
| 143 | "Unnecessary comparison of static strings.\n" |
| 144 | "The compared strings, '" + string1 + "' and '" + string2 + "', are always " + (str1==str2?"identical":"unequal") + ". " |
| 145 | "Therefore the comparison is unnecessary and looks suspicious.", (str1==str2)?CWE571:CWE570, Certainty::normal); |
| 146 | } |
| 147 | |
| 148 | void CheckStringImpl::alwaysTrueStringVariableCompareError(const Token *tok, const std::string& str1, const std::string& str2) |
| 149 | { |
no test coverage detected