Skip to content

Commit 2dd6c75

Browse files
Fix #10838 Crash/nullptr deref in getEndOfExprScope() (danmar#3870)
* Fix #10838 Crash/nullptr deref in getEndOfExprScope() * Format
1 parent 78dd29a commit 2dd6c75

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/valueflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,6 +3522,8 @@ static void valueFlowForwardLifetime(Token * tok, TokenList *tokenlist, ErrorLog
35223522
return;
35233523

35243524
const Token* expr = getLHSVariableToken(parent);
3525+
if (!expr)
3526+
return;
35253527

35263528
const Token* endOfVarScope = getEndOfExprScope(expr);
35273529

test/testvalueflow.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,19 @@ class TestValueFlow : public TestFixture {
700700
"};\n";
701701
lifetimes = lifetimeValues(code, "=");
702702
ASSERT_EQUALS(true, lifetimes.empty());
703+
704+
code = "struct T {\n" // #10838
705+
" void f();\n"
706+
" double d[4][4];\n"
707+
"};\n"
708+
"void T::f() {\n"
709+
" auto g = [this]() -> double(&)[4] {\n"
710+
" double(&q)[4] = d[0];\n"
711+
" return q;\n"
712+
" };\n"
713+
"}\n";
714+
lifetimes = lifetimeValues(code, "return"); // don't crash
715+
ASSERT_EQUALS(true, lifetimes.empty());
703716
}
704717

705718
void valueFlowArrayElement() {

0 commit comments

Comments
 (0)