fix a crasher where an invalid program that multiply defined

a protocol could smash more references in than are allocated.

llvm-svn: 48411
This commit is contained in:
Chris Lattner 2008-03-16 01:25:17 +00:00
parent f87ca0a7d1
commit 5074f8f3ef
1 changed files with 9 additions and 7 deletions

View 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;
}