Fix #10838 Crash/nullptr deref in getEndOfExprScope() (#3870)

* Fix #10838 Crash/nullptr deref in getEndOfExprScope()

* Format
This commit is contained in:
chrchr-github 2022-03-03 17:08:23 +01:00 committed by GitHub
parent 78dd29ada3
commit 2dd6c75b35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -3522,6 +3522,8 @@ static void valueFlowForwardLifetime(Token * tok, TokenList *tokenlist, ErrorLog
return;
const Token* expr = getLHSVariableToken(parent);
if (!expr)
return;
const Token* endOfVarScope = getEndOfExprScope(expr);

View File

@ -700,6 +700,19 @@ private:
"};\n";
lifetimes = lifetimeValues(code, "=");
ASSERT_EQUALS(true, lifetimes.empty());
code = "struct T {\n" // #10838
" void f();\n"
" double d[4][4];\n"
"};\n"
"void T::f() {\n"
" auto g = [this]() -> double(&)[4] {\n"
" double(&q)[4] = d[0];\n"
" return q;\n"
" };\n"
"}\n";
lifetimes = lifetimeValues(code, "return"); // don't crash
ASSERT_EQUALS(true, lifetimes.empty());
}
void valueFlowArrayElement() {