From 6ef6b0215342586ef4f7893f2d124f0e0d04493a 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 de1dfc2c9..1b92386aa 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4945,6 +4945,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 ee326ff61..bee4a3d45 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6259,6 +6259,13 @@ private: " }\n" "};\n"; valueOfTok(code, "f.c"); + + 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() {