Improve message for container type range check.

See thread:
https://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=3&t=192&start=0
This commit is contained in:
Kimmo Varis 2010-12-26 22:02:20 +02:00
parent ad89a84796
commit f5f2a2ce2a
2 changed files with 6 additions and 4 deletions

View File

@ -662,11 +662,13 @@ void CheckStl::stlBoundries()
// Error message for bad boundry usage..
void CheckStl::stlBoundriesError(const Token *tok, const std::string &container_name)
{
reportError(tok, Severity::error, "stlBoundries", container_name + " range check should use != and not < since the order of the pointers isn't guaranteed");
reportError(tok, Severity::error, "stlBoundries",
"Dangerous container iterator compare using < operator for " + container_name + "\n"
"Using < operator with container type iterators is dangerous since the order of "
"the items is not guaranteed. One should use != operator instead when comparing "
"iterators in the container.");
}
void CheckStl::if_find()
{
if (!_settings->_checkCodingStyle)

View File

@ -924,7 +924,7 @@ private:
" ;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) " + stlCont[i] + " range check should use != and not < since the order of the pointers isn't guaranteed\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous container iterator compare using < operator for " + stlCont[i] + "\n", errout.str());
}
}