Add null pointer check to fix SEGFAULT (#1499)
* Add null pointer check to fix segfault * Add first test case to reproduce problem
This commit is contained in:
parent
3e1b34dd8f
commit
61878c5e11
|
@ -2964,7 +2964,7 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab
|
||||||
(parent->str() == "return" || // MOVED in return statement
|
(parent->str() == "return" || // MOVED in return statement
|
||||||
parent->str() == "(")) // MOVED in self assignment, isOpenParenthesisMemberFunctionCallOfVarId == true
|
parent->str() == "(")) // MOVED in self assignment, isOpenParenthesisMemberFunctionCallOfVarId == true
|
||||||
continue;
|
continue;
|
||||||
if (parent && parent->astOperand1()->varId() == varId)
|
if (parent && parent->astOperand1() && parent->astOperand1()->varId() == varId)
|
||||||
continue;
|
continue;
|
||||||
const Variable *var = varTok->variable();
|
const Variable *var = varTok->variable();
|
||||||
if (!var)
|
if (!var)
|
||||||
|
|
|
@ -495,6 +495,20 @@ private:
|
||||||
" return h(std::move(x));\n"
|
" return h(std::move(x));\n"
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MovedVariable));
|
ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MovedVariable));
|
||||||
|
|
||||||
|
code = "struct X {\n"
|
||||||
|
"};\n"
|
||||||
|
"struct Data {\n"
|
||||||
|
" template<typename Fun>\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() {
|
void valueFlowCalculations() {
|
||||||
|
|
Loading…
Reference in New Issue