Skip to content

Commit

Permalink
Fix #13515 Crash in getParentLifetime() (#7171)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jan 4, 2025
1 parent 445bc7a commit 789c012
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,8 @@ const Token* getParentLifetime(const Token* tok, const Library& library)
// If any of the submembers are borrowed types then stop
if (std::any_of(it.base() - 1, members.cend() - 1, [&](const Token* tok2) {
const Token* obj = getParentLifetimeObject(tok2);
if (!obj)
return false;
const Variable* var = obj->variable();
// Check for arrays first since astIsPointer will return true, but an array is not a borrowed type
if (var && var->isArray())
Expand Down
5 changes: 5 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7350,6 +7350,11 @@ class TestValueFlow : public TestFixture {
" int j;\n"
"};\n";
(void)valueOfTok(code, "B");

code = "void f(int& r) {\n" // #13515
" [0].p = &r;\n"
"}\n";
(void)valueOfTok(code, "=");
}

void valueFlowCrash() {
Expand Down

0 comments on commit 789c012

Please sign in to comment.