Skip to content

Commit 3538cde

Browse files
smanna12yuxuanchen1997
authored andcommitted
[Clang] Prevent null pointer dereference in designated initializer check (#97220)
Summary: This patch adds an assertion in clang::SemaObjC::BuildInstanceMessage() to ensure getCurMethodDecl() returns a valid method declaration, addressing a static analyzer finding. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250674
1 parent 66a2ce8 commit 3538cde

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

clang/lib/Sema/SemaExprObjC.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,9 +3206,10 @@ ExprResult SemaObjC::BuildInstanceMessage(
32063206
}
32073207
if (!isDesignatedInitChain) {
32083208
const ObjCMethodDecl *InitMethod = nullptr;
3209+
auto *CurMD = SemaRef.getCurMethodDecl();
3210+
assert(CurMD && "Current method declaration should not be null");
32093211
bool isDesignated =
3210-
SemaRef.getCurMethodDecl()->isDesignatedInitializerForTheInterface(
3211-
&InitMethod);
3212+
CurMD->isDesignatedInitializerForTheInterface(&InitMethod);
32123213
assert(isDesignated && InitMethod);
32133214
(void)isDesignated;
32143215
Diag(SelLoc, SuperLoc.isValid() ?

0 commit comments

Comments
 (0)