diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 4785cb34e60..8175a977e79 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -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()) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 0b8a28bacc7..0cc2eb04ae5 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -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() {