Fixed #3715 (false positive checking a map bounds)
This commit is contained in:
parent
db914d7185
commit
2fbd77c5a1
|
@ -272,6 +272,13 @@ void CheckStl::stlOutOfBounds()
|
||||||
// variable id for the container variable
|
// variable id for the container variable
|
||||||
unsigned int varId = tok2->tokAt(3)->varId();
|
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()) {
|
for (const Token *tok3 = tok2->tokAt(8); tok3 && tok3 != i->classEnd; tok3 = tok3->next()) {
|
||||||
if (tok3->varId() == varId) {
|
if (tok3->varId() == varId) {
|
||||||
if (Token::simpleMatch(tok3->next(), ". size ( )"))
|
if (Token::simpleMatch(tok3->next(), ". size ( )"))
|
||||||
|
|
|
@ -505,6 +505,15 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue