[clang] c628dbd - [Clang] Prevent null pointer dereference in designated initializer check (#97220)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 24 10:41:36 PDT 2024


Author: smanna12
Date: 2024-07-24T12:41:33-05:00
New Revision: c628dbd030ff084fe5e06315ddf09a47182e9716

URL: https://github.com/llvm/llvm-project/commit/c628dbd030ff084fe5e06315ddf09a47182e9716
DIFF: https://github.com/llvm/llvm-project/commit/c628dbd030ff084fe5e06315ddf09a47182e9716.diff

LOG: [Clang] Prevent null pointer dereference in designated initializer check (#97220)

This patch adds an assertion in clang::SemaObjC::BuildInstanceMessage()
to ensure getCurMethodDecl() returns a valid method declaration,
addressing a static analyzer finding.

Added: 
    

Modified: 
    clang/lib/Sema/SemaExprObjC.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 7ccecf055feed..2751c7cec2842 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -3206,9 +3206,10 @@ ExprResult SemaObjC::BuildInstanceMessage(
     }
     if (!isDesignatedInitChain) {
       const ObjCMethodDecl *InitMethod = nullptr;
+      auto *CurMD = SemaRef.getCurMethodDecl();
+      assert(CurMD && "Current method declaration should not be null");
       bool isDesignated =
-          SemaRef.getCurMethodDecl()->isDesignatedInitializerForTheInterface(
-              &InitMethod);
+          CurMD->isDesignatedInitializerForTheInterface(&InitMethod);
       assert(isDesignated && InitMethod);
       (void)isDesignated;
       Diag(SelLoc, SuperLoc.isValid() ?


        


More information about the cfe-commits mailing list