From bb719774b132e0797e340cf4412e64a97101cd89 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Tue, 4 Jan 2011 23:04:01 +0200 Subject: [PATCH] Improve suspicious condition (string::find) message. See forum thread: https://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=3&t=192 --- lib/checkstl.cpp | 6 +++++- test/teststl.cpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index ac902ee82..e01156fa4 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -764,7 +764,11 @@ void CheckStl::if_find() void CheckStl::if_findError(const Token *tok, bool str) { if (str) - reportError(tok, Severity::warning, "stlIfStrFind", "Suspicious condition. string::find will return 0 if the string is found at position 0. If this is what you want to check then string::compare is a faster alternative because it doesn't scan through the string."); + reportError(tok, Severity::warning, "stlIfStrFind", + "Suspicious checking of string::find() return value.\n" + "string::find will return 0 if the string is found at position 0. " + "If that is wanted to check then string::compare is a faster alternative " + "because it doesn't scan through the string."); else reportError(tok, Severity::warning, "stlIfFind", "Suspicious condition. The result of find is an iterator, but it is not properly checked."); } diff --git a/test/teststl.cpp b/test/teststl.cpp index bd4c1d443..1873f33bb 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -1005,7 +1005,7 @@ private: "{\n" " if (s.find(\"abc\")) { }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. string::find will return 0 if the string is found at position 0. If this is what you want to check then string::compare is a faster alternative because it doesn't scan through the string.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious checking of string::find() return value.\n", errout.str()); }