From a241be0ecca46a7652c61fe77e4244a97a99c4a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 15 Dec 2019 20:10:12 +0100 Subject: [PATCH] Fixed #9434 (False positive: Out of bounds access when using const pointer) --- lib/valueflow.cpp | 4 +++- test/testvalueflow.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 9f2ea005b..7aeaa6ddc 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5423,7 +5423,9 @@ static bool isContainerSizeChangedByFunction(const Token *tok, int depth = 20) if (arg) { if (!arg->isReference() && !addressOf) return false; - if (arg->isConst()) + if (!addressOf && arg->isConst()) + return false; + if (arg->valueType() && arg->valueType()->constness == 1) return false; const Scope * scope = fun->functionScope; if (scope) { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 3c48f2477..aa2bde69e 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -4077,6 +4077,14 @@ private: "}"; ASSERT(tokenValues(code, "x . front").empty()); + code = "void g(std::list* const);\n" // #9434 + "void f() {\n" + " std::list x;\n" + " g(&x);\n" + " x.front();\n" + "}"; + ASSERT(tokenValues(code, "x . front").empty()); + code = "void g(const std::list&);\n" "void f() {\n" " std::list x;\n"