Skip to content

Commit 789c012

Browse files
Fix #13515 Crash in getParentLifetime() (#7171)
1 parent 445bc7a commit 789c012

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/astutils.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,8 @@ const Token* getParentLifetime(const Token* tok, const Library& library)
675675
// If any of the submembers are borrowed types then stop
676676
if (std::any_of(it.base() - 1, members.cend() - 1, [&](const Token* tok2) {
677677
const Token* obj = getParentLifetimeObject(tok2);
678+
if (!obj)
679+
return false;
678680
const Variable* var = obj->variable();
679681
// Check for arrays first since astIsPointer will return true, but an array is not a borrowed type
680682
if (var && var->isArray())

test/testvalueflow.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -7350,6 +7350,11 @@ class TestValueFlow : public TestFixture {
73507350
" int j;\n"
73517351
"};\n";
73527352
(void)valueOfTok(code, "B");
7353+
7354+
code = "void f(int& r) {\n" // #13515
7355+
" [0].p = &r;\n"
7356+
"}\n";
7357+
(void)valueOfTok(code, "=");
73537358
}
73547359

73557360
void valueFlowCrash() {

0 commit comments

Comments
 (0)