MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / alwaysTrueFalseStringCompareError

Method alwaysTrueFalseStringCompareError

lib/checkstring.cpp:136–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136void 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
148void CheckStringImpl::alwaysTrueStringVariableCompareError(const Token *tok, const std::string& str1, const std::string& str2)
149{

Callers 1

getErrorMessagesMethod · 0.80

Calls 2

reportErrorFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected