Fix ticket #248 (STL erase check broken?)

http://apps.sourceforge.net/trac/cppcheck/ticket/248
This commit is contained in:
Reijo Tomperi 2009-04-10 14:27:36 +03:00
parent c71e29829d
commit 1f53fb7149
2 changed files with 23 additions and 9 deletions

View File

@ -194,7 +194,7 @@ void CheckStl::eraseCheckLoop(const Token *it)
else if (tok->str() == "}")
{
--indentlevel;
if (indentlevel < 0)
if (indentlevel <= 0)
break;
}
else if (Token::Match(tok, "break|return|goto") || Token::simpleMatch(tok, (it->str() + " =").c_str()))

View File

@ -152,14 +152,28 @@ private:
void erase()
{
check("void f()\n"
"{\n"
" for (it = foo.begin(); it != foo.end(); ++it)\n"
" {\n"
" foo.erase(it);\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of erase\n", errout.str());
{
check("void f()\n"
"{\n"
" for (it = foo.begin(); it != foo.end(); ++it)\n"
" {\n"
" foo.erase(it);\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of erase\n", errout.str());
}
{
check("for (it = foo.begin(); it != foo.end(); ++it)\n"
"{\n"
" foo.erase(it);\n"
"}\n"
"for (it = foo.begin(); it != foo.end(); ++it)\n"
"{\n"
" foo.erase(it);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous usage of erase\n[test.cpp:7]: (error) Dangerous usage of erase\n", errout.str());
}
}
void eraseBreak()