Fixed #710 (False positive: invalid vector iterator after push_back)
This commit is contained in:
parent
482a2f9d95
commit
0b3a139b3b
|
@ -306,14 +306,14 @@ void CheckStl::pushback()
|
|||
continue;
|
||||
|
||||
const Token *pushback = 0;
|
||||
int indent3 = 0;
|
||||
unsigned int indent3 = 0;
|
||||
for (const Token *tok3 = tok2->tokAt(22); tok3; tok3 = tok3->next())
|
||||
{
|
||||
if (tok3->str() == "{")
|
||||
++indent3;
|
||||
else if (tok3->str() == "}")
|
||||
{
|
||||
if (indent3 == 0)
|
||||
if (indent3 <= 1)
|
||||
break;
|
||||
--indent3;
|
||||
}
|
||||
|
@ -333,9 +333,12 @@ void CheckStl::pushback()
|
|||
}
|
||||
|
||||
// Assigning iterator..
|
||||
if (Token::Match(tok2, "%varid% = %var% . begin ( )", iteratorid))
|
||||
if (Token::Match(tok2, "%varid% =", iteratorid))
|
||||
{
|
||||
vectorname = tok2->strAt(2);
|
||||
if (Token::Match(tok2->tokAt(2), "%var% . begin ( )"))
|
||||
vectorname = tok2->strAt(2);
|
||||
else
|
||||
vectorname = "";
|
||||
invalidIterator = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ private:
|
|||
TEST_CASE(pushback2);
|
||||
TEST_CASE(pushback3);
|
||||
TEST_CASE(pushback4);
|
||||
TEST_CASE(pushback5);
|
||||
|
||||
TEST_CASE(insert1);
|
||||
|
||||
|
@ -371,6 +372,23 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:7]: (error) Invalid pointer 'first' after push_back / push_front\n", errout.str());
|
||||
}
|
||||
|
||||
void pushback5()
|
||||
{
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" std::vector<int>::const_iterator i;\n"
|
||||
"\n"
|
||||
" for (i=v.begin(); i!=v.end(); ++i)\n"
|
||||
" {\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\n"
|
||||
" {\n"
|
||||
" v.push_back(*i);\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue