Fixed #631 (False positive matching iterator which is dereferenced)

http://sourceforge.net/apps/trac/cppcheck/ticket/631
This commit is contained in:
Slava Semushin 2009-09-01 23:49:17 +07:00
parent 0d468d97c7
commit eebe7457c9
2 changed files with 16 additions and 1 deletions

View File

@ -66,7 +66,7 @@ void CheckStl::iterators()
}
else if (Token::Match(tok2, "%var% . insert|erase ( %varid%", iteratorId))
{
if (tok2->varId() != containerId)
if (tok2->varId() != containerId && tok2->tokAt(5)->str() != ".")
iteratorsError(tok2, tok->strAt(2), tok2->str());
else if (tok2->strAt(2) == std::string("erase"))
validIterator = false;

View File

@ -37,6 +37,7 @@ private:
TEST_CASE(iterator1);
TEST_CASE(iterator2);
TEST_CASE(iterator3);
TEST_CASE(iterator4);
TEST_CASE(dereference);
TEST_CASE(dereference_member);
@ -120,6 +121,20 @@ private:
ASSERT_EQUALS("[test.cpp:6]: (error) Same iterator is used with both l1 and l2\n", errout.str());
}
void iterator4()
{
check("void foo(std::vector<std::string> &test)\n"
"{\n"
" std::set<int> result;\n"
" for (std::vector<std::string>::const_iterator cit = test.begin();\n"
" cit != test.end();\n"
" ++cit)\n"
" {\n"
" result.insert(cit->size());\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
// Dereferencing invalid pointer
void dereference()