From 261b2d58728bb19d9b00e9ef67433493a62d65ba Mon Sep 17 00:00:00 2001 From: Shafik Yaghmour Date: Thu, 5 Jun 2025 20:15:48 -0700 Subject: [PATCH] [Clang][NFC] Add nullptr check in InitializationSequence::InitializeFrom Static analysis flagged that Var could be nullptr but we were not checking in the branch and unconditionally dereferences the pointer. --- clang/lib/Sema/SemaInit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 5d870f07093ec..da56225b2f926 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -6620,7 +6620,7 @@ void InitializationSequence::InitializeFrom(Sema &S, // initializer present. However, we only do this for structure types, not // union types, because an unitialized field in a union is generally // reasonable, especially in C where unions can be used for type punning. - if (!Initializer && !Rec->isUnion() && !Rec->isInvalidDecl()) { + if (Var && !Initializer && !Rec->isUnion() && !Rec->isInvalidDecl()) { if (const FieldDecl *FD = getConstField(Rec)) { unsigned DiagID = diag::warn_default_init_const_field_unsafe; if (Var->getStorageDuration() == SD_Static ||