From: Fariborz Jahanian Date: Mon, 8 Oct 2007 16:07:03 +0000 (+0000) Subject: Return NULL on invalid protocol. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0332b6c83856d24cd1bbf734322843fcc83fa379;p=clang Return NULL on invalid protocol. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42754 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 0b812cdd48..574f1f6166 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -1065,11 +1065,14 @@ Sema::DeclTy *Sema::ActOnStartCategoryInterface(Scope* S, ObjcInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName); ObjcCategoryDecl *CDecl = new ObjcCategoryDecl(AtInterfaceLoc, NumProtoRefs, CategoryName); + bool err = false; CDecl->setClassInterface(IDecl); /// Check that class of this category is already completely declared. - if (!IDecl || IDecl->isForwardDecl()) + if (!IDecl || IDecl->isForwardDecl()) { Diag(ClassLoc, diag::err_undef_interface, ClassName->getName()); + err = true; + } else { /// Check for duplicate interface declaration for this category ObjcCategoryDecl *CDeclChain; @@ -1078,6 +1081,7 @@ Sema::DeclTy *Sema::ActOnStartCategoryInterface(Scope* S, if (CDeclChain->getIdentifier() == CategoryName) { Diag(CategoryLoc, diag::err_dup_category_def, ClassName->getName(), CategoryName->getName()); + err = true; break; } } @@ -1089,14 +1093,16 @@ Sema::DeclTy *Sema::ActOnStartCategoryInterface(Scope* S, for (unsigned int i = 0; i != NumProtoRefs; i++) { ObjcProtocolDecl* RefPDecl = getObjCProtocolDecl(S, ProtoRefNames[i], CategoryLoc); - if (!RefPDecl || RefPDecl->isForwardDecl()) + if (!RefPDecl || RefPDecl->isForwardDecl()) { Diag(CategoryLoc, diag::err_undef_protocolref, ProtoRefNames[i]->getName(), CategoryName->getName()); + err = true; + } CDecl->setCatReferencedProtocols((int)i, RefPDecl); } - return CDecl; + return err ? 0 : CDecl; } /// ActOnStartCategoryImplementation - Perform semantic checks on the