Skip to content

Commit 61878c5

Browse files
knowledge4igordanmar
authored andcommitted
Add null pointer check to fix SEGFAULT (#1499)
* Add null pointer check to fix segfault * Add first test case to reproduce problem
1 parent 3e1b34d commit 61878c5

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2964,7 +2964,7 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab
29642964
(parent->str() == "return" || // MOVED in return statement
29652965
parent->str() == "(")) // MOVED in self assignment, isOpenParenthesisMemberFunctionCallOfVarId == true
29662966
continue;
2967-
if (parent && parent->astOperand1()->varId() == varId)
2967+
if (parent && parent->astOperand1() && parent->astOperand1()->varId() == varId)
29682968
continue;
29692969
const Variable *var = varTok->variable();
29702970
if (!var)

test/testvalueflow.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,20 @@ class TestValueFlow : public TestFixture {
495495
" return h(std::move(x));\n"
496496
"}";
497497
ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MovedVariable));
498+
499+
code = "struct X {\n"
500+
"};\n"
501+
"struct Data {\n"
502+
" template<typename Fun>\n"
503+
" void foo(Fun f) {}\n"
504+
"};\n"
505+
"Data g(X value) { return Data(); }\n"
506+
"void f() {\n"
507+
" X x;\n"
508+
" g(std::move(x)).foo([=](int value) mutable {;});\n"
509+
" X y=x;\n"
510+
"}";
511+
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 11U, ValueFlow::Value::MovedVariable));
498512
}
499513

500514
void valueFlowCalculations() {

0 commit comments

Comments
 (0)