Merge branch 'master' of git@github.com:danmar/cppcheck
This commit is contained in:
commit
a3a55547d8
|
@ -354,7 +354,7 @@ void CheckStl::pushback()
|
||||||
// Assigning iterator..
|
// Assigning iterator..
|
||||||
if (Token::Match(tok2, "%varid% =", iteratorid))
|
if (Token::Match(tok2, "%varid% =", iteratorid))
|
||||||
{
|
{
|
||||||
if (Token::Match(tok2->tokAt(2), "%var% . begin ( )"))
|
if (Token::Match(tok2->tokAt(2), "%var% . begin|end|rbegin|rend ( )"))
|
||||||
vectorname = tok2->strAt(2);
|
vectorname = tok2->strAt(2);
|
||||||
else
|
else
|
||||||
vectorname = "";
|
vectorname = "";
|
||||||
|
@ -368,7 +368,7 @@ void CheckStl::pushback()
|
||||||
// Using invalid iterator..
|
// Using invalid iterator..
|
||||||
if (invalidIterator)
|
if (invalidIterator)
|
||||||
{
|
{
|
||||||
if (Token::Match(tok2, "++|--|*|+|-|(|, %varid%", iteratorid))
|
if (Token::Match(tok2, "++|--|*|+|-|(|,|=|!= %varid%", iteratorid))
|
||||||
pushbackError(tok2, tok2->strAt(1));
|
pushbackError(tok2, tok2->strAt(1));
|
||||||
if (Token::Match(tok2, "%varid% ++|--|+|-", iteratorid))
|
if (Token::Match(tok2, "%varid% ++|--|+|-", iteratorid))
|
||||||
pushbackError(tok2, tok2->str());
|
pushbackError(tok2, tok2->str());
|
||||||
|
|
|
@ -58,6 +58,7 @@ private:
|
||||||
TEST_CASE(pushback5);
|
TEST_CASE(pushback5);
|
||||||
TEST_CASE(pushback6);
|
TEST_CASE(pushback6);
|
||||||
TEST_CASE(pushback7);
|
TEST_CASE(pushback7);
|
||||||
|
TEST_CASE(pushback8);
|
||||||
|
|
||||||
TEST_CASE(insert1);
|
TEST_CASE(insert1);
|
||||||
|
|
||||||
|
@ -449,6 +450,23 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (error) After push_back or push_front, the iterator 'it' may be invalid\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (error) After push_back or push_front, the iterator 'it' may be invalid\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pushback8()
|
||||||
|
{
|
||||||
|
check("void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" std::vector<int> ints;\n"
|
||||||
|
" std::vector<int>::const_iterator end = ints.end();\n"
|
||||||
|
" ints.push_back(10);\n"
|
||||||
|
" std::vector<int>::iterator it;\n"
|
||||||
|
" unsigned int sum = 0;\n"
|
||||||
|
" for (it = ints.begin(); it != end; ++it)\n"
|
||||||
|
" {\n"
|
||||||
|
" sum += *it;\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:8]: (error) After push_back or push_front, the iterator 'end' may be invalid\n", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void insert1()
|
void insert1()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue