| 327 | } |
| 328 | |
| 329 | void 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") |
no test coverage detected