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:
parent
66e8b7bc1e
commit
bb719774b1
|
@ -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.");
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue