From 60c1eef6592f7ed49ccc2412923cc7ea9f04c67d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 23 Jun 2022 20:26:47 +0200 Subject: [PATCH] Fix FP containerOutOfBounds with std::map (#4230) --- lib/checkstl.cpp | 2 +- test/teststl.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 9b3a5effe..fdf0bf5f6 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -128,7 +128,7 @@ void CheckStl::outOfBounds() for (const Scope *function : mTokenizer->getSymbolDatabase()->functionScopes) { for (const Token *tok = function->bodyStart; tok != function->bodyEnd; tok = tok->next()) { const Library::Container *container = getLibraryContainer(tok); - if (!container) + if (!container || container->stdAssociativeLike) continue; const Token * parent = astParentSkipParens(tok); const Token* accessTok = parent; diff --git a/test/teststl.cpp b/test/teststl.cpp index b4d686229..0caa695a0 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -854,6 +854,12 @@ private: " return d;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + checkNormal("std::string f() {\n" + " std::map m = { { 1, \"1\" } };\n" + " return m.at(1);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void outOfBoundsSymbolic()