From be4ae66e3689330f484bc98759d42d5eb8cec710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 12 Aug 2018 08:01:15 +0200 Subject: [PATCH] Fix wrong message --- lib/checkstring.cpp | 4 +++- test/teststring.cpp | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index b2b1cb003..643778055 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -322,10 +322,12 @@ void CheckString::incorrectStringCompareError(const Token *tok, const std::strin void CheckString::incorrectStringBooleanError(const Token *tok, const std::string& string) { const bool charLiteral = string[0] == '\''; + const std::string literalType = charLiteral ? "char" : "string"; + const std::string result = (string == "\'\\0\'") ? "false" : "true"; reportError(tok, Severity::warning, 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); } //--------------------------------------------------------------------------- diff --git a/test/teststring.cpp b/test/teststring.cpp index 39b1a5cae..5b79a7460 100644 --- a/test/teststring.cpp +++ b/test/teststring.cpp @@ -596,6 +596,11 @@ private: " if('\\0'){}\n" "}"); 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() {