Fixed #631 (False positive matching iterator which is dereferenced)
http://sourceforge.net/apps/trac/cppcheck/ticket/631
This commit is contained in:
parent
0d468d97c7
commit
eebe7457c9
|
@ -66,7 +66,7 @@ void CheckStl::iterators()
|
||||||
}
|
}
|
||||||
else if (Token::Match(tok2, "%var% . insert|erase ( %varid%", iteratorId))
|
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());
|
iteratorsError(tok2, tok->strAt(2), tok2->str());
|
||||||
else if (tok2->strAt(2) == std::string("erase"))
|
else if (tok2->strAt(2) == std::string("erase"))
|
||||||
validIterator = false;
|
validIterator = false;
|
||||||
|
|
|
@ -37,6 +37,7 @@ private:
|
||||||
TEST_CASE(iterator1);
|
TEST_CASE(iterator1);
|
||||||
TEST_CASE(iterator2);
|
TEST_CASE(iterator2);
|
||||||
TEST_CASE(iterator3);
|
TEST_CASE(iterator3);
|
||||||
|
TEST_CASE(iterator4);
|
||||||
|
|
||||||
TEST_CASE(dereference);
|
TEST_CASE(dereference);
|
||||||
TEST_CASE(dereference_member);
|
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());
|
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
|
// Dereferencing invalid pointer
|
||||||
void dereference()
|
void dereference()
|
||||||
|
|
Loading…
Reference in New Issue