Improve suspicious condition (string::find) message.

See forum thread:
https://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=3&t=192
This commit is contained in:
Kimmo Varis 2011-01-04 23:04:01 +02:00
parent 66e8b7bc1e
commit bb719774b1
2 changed files with 6 additions and 2 deletions

View File

@ -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.");
}

View File

@ -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());
}