From bb640c4879a9d94d4acb475e850eff9971a0e3a5 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Wed, 6 Apr 2022 12:00:05 -0500 Subject: [PATCH] Fix 10950: Crash on function declaration (#3979) * Fix 10950: Crash on function declaration * Format --- lib/valueflow.cpp | 2 ++ test/testvalueflow.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 04e4a71d1..667666ad6 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -7649,6 +7649,8 @@ static void valueFlowContainerSize(TokenList* tokenlist, for (const Variable *var : symboldatabase->variableList()) { if (!var) continue; + if (!var->scope() || !var->scope()->bodyEnd || !var->scope()->bodyStart) + continue; if (!var->valueType() || !var->valueType()->container) continue; if (!astIsContainer(var->nameToken())) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 1ecd16c67..9756cfb50 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6434,6 +6434,12 @@ private: " std::cout << (void*)(std::shared_ptr{ g() }.get());\n" "}\n"; valueOfTok(code, "."); + + code = "class T;\n" + "struct S {\n" + " void f(std::array& a);\n" + "};\n"; + valueOfTok(code, "a"); } void valueFlowHang() {