From 2fbd77c5a14f9cf2d3cbff577e1c7daeff95f273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 7 May 2012 12:03:33 -0700 Subject: [PATCH] Fixed #3715 (false positive checking a map bounds) --- lib/checkstl.cpp | 7 +++++++ test/teststl.cpp | 9 +++++++++ 2 files changed, 16 insertions(+) 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()); + } }