diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 08fc247d2..fc462f115 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -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 ( )")) diff --git a/test/teststl.cpp b/test/teststl.cpp index 51af686d2..d19325b78 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -505,6 +505,15 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); } + + { + check("void f(const std::map &data) {\n" + " int i = x;" + " for (int i = 5; i <= data.size(); i++)\n" + " data[i] = 0;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } }