From: Kevin Enderby Date: Tue, 13 Oct 2015 20:48:04 +0000 (+0000) Subject: Tweak to r250117 and change to use ErrorOr and drop isSizeValid for X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1cd4c56bf6d6a4784d7606ea9b9ee005835dedd7;p=oota-llvm.git Tweak to r250117 and change to use ErrorOr and drop isSizeValid for ArchiveMemberHeader, suggestion by Rafael EspĂ­ndola. Also The clang-x86-win2008-selfhost bot still does not like the malformed-machos 00000031.a test, so removing it for now. All the other bots are fine with it however. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250222 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/Archive.h b/include/llvm/Object/Archive.h index 5271dde5721..32c72a0cc3d 100644 --- a/include/llvm/Object/Archive.h +++ b/include/llvm/Object/Archive.h @@ -37,8 +37,7 @@ struct ArchiveMemberHeader { llvm::StringRef getName() const; /// Members are not larger than 4GB. - uint32_t getSize() const; - bool isSizeValid() const; + ErrorOr getSize() const; sys::fs::perms getAccessMode() const; sys::TimeValue getLastModified() const; diff --git a/lib/Object/Archive.cpp b/lib/Object/Archive.cpp index b0e0881c789..667732baa27 100644 --- a/lib/Object/Archive.cpp +++ b/lib/Object/Archive.cpp @@ -43,20 +43,13 @@ StringRef ArchiveMemberHeader::getName() const { return llvm::StringRef(Name, end); } -uint32_t ArchiveMemberHeader::getSize() const { +ErrorOr ArchiveMemberHeader::getSize() const { uint32_t Ret; if (llvm::StringRef(Size, sizeof(Size)).rtrim(" ").getAsInteger(10, Ret)) - llvm_unreachable("Size is not a decimal number."); + return object_error::parse_failed; return Ret; } -bool ArchiveMemberHeader::isSizeValid() const { - uint32_t Ret; - if (llvm::StringRef(Size, sizeof(Size)).rtrim(" ").getAsInteger(10, Ret)) - return false; - return true; -} - sys::fs::perms ArchiveMemberHeader::getAccessMode() const { unsigned Ret; if (StringRef(AccessMode, sizeof(AccessMode)).rtrim(" ").getAsInteger(8, Ret)) @@ -96,11 +89,6 @@ Archive::Child::Child(const Archive *Parent, const char *Start) uint64_t Size = sizeof(ArchiveMemberHeader); Data = StringRef(Start, Size); - // Check to make sure the size is valid. - const ArchiveMemberHeader *Header = - reinterpret_cast(Data.data()); - if (!Header->isSizeValid()) - return; if (!isThinMember()) { Size += getRawSize(); Data = StringRef(Start, Size); @@ -119,13 +107,20 @@ Archive::Child::Child(const Archive *Parent, const char *Start) } uint64_t Archive::Child::getSize() const { - if (Parent->IsThin) - return getHeader()->getSize(); + if (Parent->IsThin) { + ErrorOr Size = getHeader()->getSize(); + if (Size.getError()) + return 0; + return Size.get(); + } return Data.size() - StartOfFile; } uint64_t Archive::Child::getRawSize() const { - return getHeader()->getSize(); + ErrorOr Size = getHeader()->getSize(); + if (Size.getError()) + return 0; + return Size.get(); } bool Archive::Child::isThinMember() const { diff --git a/test/tools/llvm-objdump/X86/malformed-machos.test b/test/tools/llvm-objdump/X86/malformed-machos.test index c98d08ca21d..a47e43443c5 100644 --- a/test/tools/llvm-objdump/X86/malformed-machos.test +++ b/test/tools/llvm-objdump/X86/malformed-machos.test @@ -39,10 +39,3 @@ # RUN: | FileCheck -check-prefix=m0337 %s # m0337: subq $16, %rsp - -# RUN: llvm-objdump -arch x86_64 -macho -disassemble \ -# RUN: %p/Inputs/malformed-machos/00000031.a \ -# RUN: | FileCheck -check-prefix=0031a %s - -# 0031a: Archive -