Fixed #2451 (False positive when incrementing map value via iterator)

This commit is contained in:
Daniel Marjamäki 2011-01-14 19:50:07 +01:00
parent 708a75e363
commit 00b49a51da
2 changed files with 10 additions and 3 deletions

View File

@ -962,11 +962,11 @@ void CheckStl::missingComparison()
break;
--indentlevel;
}
else if (tok3->varId() == iteratorId && Token::simpleMatch(tok3->next(), "++"))
else if (Token::Match(tok3, "%varid% ++", iteratorId))
incrementToken = tok3;
else if (tok3->str() == "++" && tok3->next() && tok3->next()->varId() == iteratorId)
else if (Token::Match(tok3->previous(), "++ %varid% !!.", iteratorId))
incrementToken = tok3;
else if (tok3->varId() == iteratorId && Token::Match(tok3->next(), "!=|=="))
else if (Token::Match(tok3, "%varid% !=|==", iteratorId))
incrementToken = 0;
else if (tok3->str() == "break" || tok3->str() == "return")
incrementToken = 0;

View File

@ -1080,6 +1080,13 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (warning) Missing bounds check for extra iterator increment in loop.\n", errout.str());
check("void f(std::map<int,int> &ints) {\n"
" for (std::map<int,int>::iterator it = ints.begin(); it != ints.end(); ++it) {\n"
" ++it->second;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void missingInnerComparison2()