From 5074f8f3ef932e502ec99b6015482002f2d34936 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 16 Mar 2008 01:25:17 +0000 Subject: [PATCH] fix a crasher where an invalid program that multiply defined a protocol could smash more references in than are allocated. llvm-svn: 48411 --- clang/lib/Sema/SemaDeclObjC.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index af57d09ce627..3b8baea519fd 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -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; }