[PATCH] D53561: [clang] Fix a null pointer dereference.

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 23 02:27:29 PDT 2018


kadircet created this revision.
kadircet added reviewers: sammccall, ioeric, hokein.
Herald added a subscriber: cfe-commits.

Sometimes expression inside switch statement can be invalid, for
example type might be incomplete. In those cases code were causing a null
pointer dereference. This patch fixes that.


Repository:
  rC Clang

https://reviews.llvm.org/D53561

Files:
  lib/Sema/SemaCodeComplete.cpp


Index: lib/Sema/SemaCodeComplete.cpp
===================================================================
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -4419,6 +4419,9 @@
     return;
 
   SwitchStmt *Switch = getCurFunction()->SwitchStack.back().getPointer();
+  // Condition expression might be invalid, do not continue in this case.
+  if (!Switch->getCond())
+    return;
   QualType type = Switch->getCond()->IgnoreImplicit()->getType();
   if (!type->isEnumeralType()) {
     CodeCompleteExpressionData Data(type);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53561.170592.patch
Type: text/x-patch
Size: 545 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181023/faf2986c/attachment.bin>


More information about the cfe-commits mailing list