Fixed #932 (false positive: Dereferenced iterator 'i' has been erased)
This commit is contained in:
parent
293631745a
commit
51f983629b
|
@ -73,6 +73,13 @@ void CheckStl::iterators()
|
||||||
|
|
||||||
tok2 = tok2->tokAt(4);
|
tok2 = tok2->tokAt(4);
|
||||||
}
|
}
|
||||||
|
else if (Token::Match(tok2, "%varid% = %var% . erase (", iteratorId))
|
||||||
|
{
|
||||||
|
validIterator = true;
|
||||||
|
tok2 = tok2->tokAt(5)->link();
|
||||||
|
if (!tok2)
|
||||||
|
break;
|
||||||
|
}
|
||||||
else if (!validIterator && Token::Match(tok2, "* %varid%", iteratorId))
|
else if (!validIterator && Token::Match(tok2, "* %varid%", iteratorId))
|
||||||
{
|
{
|
||||||
dereferenceErasedError(tok2, tok2->strAt(1));
|
dereferenceErasedError(tok2, tok2->strAt(1));
|
||||||
|
|
|
@ -258,28 +258,34 @@ private:
|
||||||
|
|
||||||
void erase()
|
void erase()
|
||||||
{
|
{
|
||||||
{
|
check("void f()\n"
|
||||||
check("void f()\n"
|
"{\n"
|
||||||
"{\n"
|
" for (it = foo.begin(); it != foo.end(); ++it)\n"
|
||||||
" for (it = foo.begin(); it != foo.end(); ++it)\n"
|
" {\n"
|
||||||
" {\n"
|
" foo.erase(it);\n"
|
||||||
" foo.erase(it);\n"
|
" }\n"
|
||||||
" }\n"
|
"}\n");
|
||||||
"}\n");
|
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of erase\n", errout.str());
|
||||||
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());
|
||||||
|
|
||||||
|
check("void f(std::list<int> &ints)\n"
|
||||||
|
"{\n"
|
||||||
|
" std::list<int>::iterator i = ints.begin();\n"
|
||||||
|
" i = ints.erase(i);\n"
|
||||||
|
" *i = 0;\n"
|
||||||
|
" \n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", 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()
|
void eraseBreak()
|
||||||
|
|
Loading…
Reference in New Issue