Fixed #3715 (false positive checking a map bounds)

This commit is contained in:
Daniel Marjamäki 2012-05-07 12:03:33 -07:00
parent db914d7185
commit 2fbd77c5a1
2 changed files with 16 additions and 0 deletions

View File

@ -272,6 +272,13 @@ void CheckStl::stlOutOfBounds()
// variable id for the container variable
unsigned int varId = tok2->tokAt(3)->varId();
// Is it a vector?
const Variable *container = symbolDatabase->getVariableFromVarId(varId);
if (!container)
continue;
if (!Token::simpleMatch(container->typeStartToken(), "std :: vector <"))
continue;
for (const Token *tok3 = tok2->tokAt(8); tok3 && tok3 != i->classEnd; tok3 = tok3->next()) {
if (tok3->varId() == varId) {
if (Token::simpleMatch(tok3->next(), ". size ( )"))

View File

@ -505,6 +505,15 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
}
{
check("void f(const std::map<int,int> &data) {\n"
" int i = x;"
" for (int i = 5; i <= data.size(); i++)\n"
" data[i] = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
}