[PATCH] D139148: Fix nullptr dereference found by Coverity static analysis tool

Sindhu Chittireddy via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 1 14:50:39 PST 2022


schittir created this revision.
Herald added a project: All.
schittir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adding nullptr check for 'Initializer'


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139148

Files:
  clang/lib/Sema/SemaInit.cpp


Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5962,9 +5962,10 @@
     if (Kind.getKind() == InitializationKind::IK_Direct ||
         (Kind.getKind() == InitializationKind::IK_Copy &&
          (Context.hasSameUnqualifiedType(SourceType, DestType) ||
-          S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType))))
-      TryConstructorInitialization(S, Entity, Kind, Args,
-                                   DestType, DestType, *this);
+          (Initializer &&
+           S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType)))))
+      TryConstructorInitialization(S, Entity, Kind, Args, DestType, DestType,
+                                   *this);
     //     - Otherwise (i.e., for the remaining copy-initialization cases),
     //       user-defined conversion sequences that can convert from the source
     //       type to the destination type or (when a conversion function is


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139148.479441.patch
Type: text/x-patch
Size: 1046 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221201/19586013/attachment-0001.bin>


More information about the cfe-commits mailing list