[PATCH] D31591: Fix a bug which access nullptr and cause segmentation fault

Yuka Takahashi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 3 07:51:24 PDT 2017


yamaguchi updated this revision to Diff 93860.
yamaguchi added a comment.

Moved comment inside if (ExistingInit).


https://reviews.llvm.org/D31591

Files:
  SemaInit.cpp


Index: SemaInit.cpp
===================================================================
--- SemaInit.cpp
+++ SemaInit.cpp
@@ -2260,15 +2260,17 @@
           assert(StructuredList->getNumInits() == 1
                  && "A union should never have more than one initializer!");
 
-          // We're about to throw away an initializer, emit warning.
-          SemaRef.Diag(D->getFieldLoc(),
-                       diag::warn_initializer_overrides)
-            << D->getSourceRange();
           Expr *ExistingInit = StructuredList->getInit(0);
-          SemaRef.Diag(ExistingInit->getLocStart(),
-                       diag::note_previous_initializer)
-            << /*FIXME:has side effects=*/0
-            << ExistingInit->getSourceRange();
+          if (ExistingInit) {
+            // We're about to throw away an initializer, emit warning.
+            SemaRef.Diag(D->getFieldLoc(),
+                         diag::warn_initializer_overrides)
+              << D->getSourceRange();
+            SemaRef.Diag(ExistingInit->getLocStart(),
+                         diag::note_previous_initializer)
+              << /*FIXME:has side effects=*/0
+              << ExistingInit->getSourceRange();
+          }
 
           // remove existing initializer
           StructuredList->resizeInits(SemaRef.Context, 0);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31591.93860.patch
Type: text/x-patch
Size: 1323 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170403/a6ef80c3/attachment.bin>


More information about the cfe-commits mailing list