From 915ae4b845c51d41ecf582622a3e107a1e3a642f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 2 Mar 2022 21:12:37 +0100 Subject: [PATCH] ValueFlow: Fix crash --- lib/valueflow.cpp | 2 ++ test/testvalueflow.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 1f2a460e7..3ac241912 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5107,6 +5107,8 @@ static void valueFlowForwardAssign(Token* const tok, // Skip RHS const Token * nextExpression = tok->astParent() ? nextAfterAstRightmostLeaf(tok->astParent()) : tok->next(); + if (!nextExpression) + return; for (ValueFlow::Value& value : values) { if (value.isSymbolicValue()) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index ea94938ea..3e2669979 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6397,6 +6397,13 @@ private: " s;\n" "}\n"; valueOfTok(code, "s"); + + code = "int f(int value) { return 0; }\n" + "std::shared_ptr g() {\n" + " static const std::shared_ptr x{ new M{} };\n" + " return x;\n" + "}\n"; + valueOfTok(code, "x"); } void valueFlowHang() {