Fix wrong message
This commit is contained in:
parent
a9ae897f8c
commit
be4ae66e36
|
@ -322,10 +322,12 @@ void CheckString::incorrectStringCompareError(const Token *tok, const std::strin
|
||||||
void CheckString::incorrectStringBooleanError(const Token *tok, const std::string& string)
|
void CheckString::incorrectStringBooleanError(const Token *tok, const std::string& string)
|
||||||
{
|
{
|
||||||
const bool charLiteral = string[0] == '\'';
|
const bool charLiteral = string[0] == '\'';
|
||||||
|
const std::string literalType = charLiteral ? "char" : "string";
|
||||||
|
const std::string result = (string == "\'\\0\'") ? "false" : "true";
|
||||||
reportError(tok,
|
reportError(tok,
|
||||||
Severity::warning,
|
Severity::warning,
|
||||||
charLiteral ? "incorrectCharBooleanError" : "incorrectStringBooleanError",
|
charLiteral ? "incorrectCharBooleanError" : "incorrectStringBooleanError",
|
||||||
"Conversion of " + std::string(charLiteral ? "char" : "string") + " literal " + string + " to bool always evaluates to true.", CWE571, false);
|
"Conversion of " + literalType + " literal " + string + " to bool always evaluates to " + result + '.', CWE571, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -596,6 +596,11 @@ private:
|
||||||
" if('\\0'){}\n"
|
" if('\\0'){}\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f() {\n"
|
||||||
|
" if('\\0' || cond){}\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of char literal '\\0' to bool always evaluates to false.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void deadStrcmp() {
|
void deadStrcmp() {
|
||||||
|
|
Loading…
Reference in New Issue