]> granicus.if.org Git - clang/commitdiff
fix a crasher where an invalid program that multiply defined
authorChris Lattner <sabre@nondot.org>
Sun, 16 Mar 2008 01:25:17 +0000 (01:25 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 16 Mar 2008 01:25:17 +0000 (01:25 +0000)
a protocol could smash more references in than are allocated.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48411 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclObjC.cpp

index af57d09ce627124049bef40cca9436d1a8571fb3..3b8baea519fd2bc1db09e1b8ae3e9824743facca 100644 (file)
@@ -202,17 +202,19 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface(
   ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolName];
   if (PDecl) {
     // Protocol already seen. Better be a forward protocol declaration
-    if (!PDecl->isForwardDecl())
+    if (!PDecl->isForwardDecl()) {
       Diag(ProtocolLoc, diag::err_duplicate_protocol_def, 
            ProtocolName->getName());
-    else {
-      PDecl->setForwardDecl(false);
-      PDecl->AllocReferencedProtocols(NumProtoRefs);
+      // Just return the protocol we already had.
+      // FIXME: don't leak the objects passed in!
+      return PDecl;
     }
-  }
-  else {
+    
+    PDecl->setForwardDecl(false);
+    PDecl->AllocReferencedProtocols(NumProtoRefs);
+  } else {
     PDecl = ObjCProtocolDecl::Create(Context, AtProtoInterfaceLoc, NumProtoRefs, 
-                                     ProtocolName);
+                                     ProtocolName, false);
     ObjCProtocols[ProtocolName] = PDecl;
   }