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

Method incorrectStringBooleanError

lib/checkstring.cpp:329–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327}
328
329void CheckStringImpl::incorrectStringBooleanError(const Token *tok, const std::string& string)
330{
331 const bool charLiteral = isCharLiteral(string);
332 const std::string literalType = charLiteral ? "char" : "string";
333 const std::string result = bool_to_string(getCharLiteral(string) != "\\0");
334 reportError(tok,
335 Severity::warning,
336 charLiteral ? "incorrectCharBooleanError" : "incorrectStringBooleanError",
337 "Conversion of " + literalType + " literal " + string + " to bool always evaluates to " + result + '.', CWE571, Certainty::normal);
338}
339
340//---------------------------------------------------------------------------
341// always true: strcmp(str,"a")==0 || strcmp(str,"b")

Callers 1

getErrorMessagesMethod · 0.80

Calls 4

bool_to_stringFunction · 0.85
getCharLiteralFunction · 0.85
isCharLiteralFunction · 0.70
reportErrorFunction · 0.70

Tested by

no test coverage detected