Don't reject an empty archive.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186159 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2013-07-12 13:32:28 +00:00
parent 7ffc422659
commit 5e102c6c48
3 changed files with 10 additions and 4 deletions

View File

@@ -212,9 +212,9 @@ error_code Archive::Child::getAsBinary(OwningPtr<Binary> &Result) const {
Archive::Archive(MemoryBuffer *source, error_code &ec) Archive::Archive(MemoryBuffer *source, error_code &ec)
: Binary(Binary::ID_Archive, source), SymbolTable(end_children()) { : Binary(Binary::ID_Archive, source), SymbolTable(end_children()) {
// Check for sufficient magic. // Check for sufficient magic.
if (!source || source->getBufferSize() assert(source);
< (8 + sizeof(ArchiveMemberHeader)) // Smallest archive. if (source->getBufferSize() < 8 ||
|| StringRef(source->getBufferStart(), 8) != Magic) { StringRef(source->getBufferStart(), 8) != Magic) {
ec = object_error::invalid_file_type; ec = object_error::invalid_file_type;
return; return;
} }
@@ -224,7 +224,7 @@ Archive::Archive(MemoryBuffer *source, error_code &ec)
child_iterator e = end_children(); child_iterator e = end_children();
if (i == e) { if (i == e) {
ec = object_error::parse_failed; ec = object_error::success;
return; return;
} }
@@ -314,6 +314,8 @@ Archive::Archive(MemoryBuffer *source, error_code &ec)
} }
Archive::child_iterator Archive::begin_children(bool skip_internal) const { Archive::child_iterator Archive::begin_children(bool skip_internal) const {
if (Data->getBufferSize() == 8) // empty archive.
return end_children();
const char *Loc = Data->getBufferStart() + strlen(Magic); const char *Loc = Data->getBufferStart() + strlen(Magic);
Child c(this, Loc); Child c(this, Loc);
// Skip internals at the beginning of an archive. // Skip internals at the beginning of an archive.

View File

@@ -0,0 +1 @@
!<arch>

View File

@@ -30,3 +30,6 @@ RUN: llvm-nm %p/Inputs/archive-test.a-gnu-minimal
And don't crash when asked to print a non existing symtab. And don't crash when asked to print a non existing symtab.
RUN: llvm-nm -s %p/Inputs/archive-test.a-gnu-minimal RUN: llvm-nm -s %p/Inputs/archive-test.a-gnu-minimal
Don't reject an empty archive.
RUN: llvm-nm %p/Inputs/archive-test.a-empty