Detects invalid iterator inside for() when postfix form of increment used.
This commit is contained in:
parent
5285635354
commit
7e2208b5cc
|
@ -318,7 +318,7 @@ void CheckStl::pushback()
|
||||||
tok2 = tok2->tokAt(2);
|
tok2 = tok2->tokAt(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok2, "%varid% = %var% . begin ( ) ; %varid% != %var% . end ( ) ; ++ %varid% ) {", iteratorid))
|
if (Token::Match(tok2, "%varid% = %var% . begin ( ) ; %varid% != %var% . end ( ) ; ++| %varid% ++| ) {", iteratorid))
|
||||||
{
|
{
|
||||||
const unsigned int vectorid(tok2->tokAt(2)->varId());
|
const unsigned int vectorid(tok2->tokAt(2)->varId());
|
||||||
if (vectorid == 0)
|
if (vectorid == 0)
|
||||||
|
|
|
@ -57,6 +57,7 @@ private:
|
||||||
TEST_CASE(pushback4);
|
TEST_CASE(pushback4);
|
||||||
TEST_CASE(pushback5);
|
TEST_CASE(pushback5);
|
||||||
TEST_CASE(pushback6);
|
TEST_CASE(pushback6);
|
||||||
|
TEST_CASE(pushback7);
|
||||||
|
|
||||||
TEST_CASE(insert1);
|
TEST_CASE(insert1);
|
||||||
|
|
||||||
|
@ -421,6 +422,21 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:9]: (error) After push_back or push_front, the iterator 'it' may be invalid\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:9]: (error) After push_back or push_front, the iterator 'it' may be invalid\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pushback7()
|
||||||
|
{
|
||||||
|
check("void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" std::vector<int> foo;\n"
|
||||||
|
" foo.push_back(10);\n"
|
||||||
|
" std::vector<int>::iterator it;\n"
|
||||||
|
" for (it = foo.begin(); it != foo.end(); it++)\n"
|
||||||
|
" {\n"
|
||||||
|
" foo.push_back(123);\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:8]: (error) After push_back or push_front, the iterator 'it' may be invalid\n", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void insert1()
|
void insert1()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue