From 61878c5e111c23b19bcddc7d5c3a602365662f68 Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 2 Dec 2018 16:36:01 +0300 Subject: [PATCH] Add null pointer check to fix SEGFAULT (#1499) * Add null pointer check to fix segfault * Add first test case to reproduce problem --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 611fcbde8..87dae7d85 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2964,7 +2964,7 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab (parent->str() == "return" || // MOVED in return statement parent->str() == "(")) // MOVED in self assignment, isOpenParenthesisMemberFunctionCallOfVarId == true continue; - if (parent && parent->astOperand1()->varId() == varId) + if (parent && parent->astOperand1() && parent->astOperand1()->varId() == varId) continue; const Variable *var = varTok->variable(); if (!var) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index be8528c87..3bb661d74 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -495,6 +495,20 @@ private: " return h(std::move(x));\n" "}"; ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MovedVariable)); + + code = "struct X {\n" + "};\n" + "struct Data {\n" + " template\n" + " void foo(Fun f) {}\n" + "};\n" + "Data g(X value) { return Data(); }\n" + "void f() {\n" + " X x;\n" + " g(std::move(x)).foo([=](int value) mutable {;});\n" + " X y=x;\n" + "}"; + TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 11U, ValueFlow::Value::MovedVariable)); } void valueFlowCalculations() {