From: Rafael Espindola Date: Tue, 1 Nov 2016 20:24:22 +0000 (+0000) Subject: Use the existing std::error_code out parameter. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c24244e8de5ee74b4f14e239a8bad450535568dd;p=llvm Use the existing std::error_code out parameter. This avoids calling exit with a partially constructed object. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285738 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 2c715bffa2f..10f61ad2f28 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -324,9 +324,10 @@ ELFFile::ELFFile(StringRef Object, std::error_code &EC) Header = reinterpret_cast(base()); if (Header->e_shoff == 0) { - if (Header->e_shnum != 0) - report_fatal_error( - "e_shnum should be zero if a file has no section header table"); + if (Header->e_shnum != 0) { + // e_shnum should be zero if a file has no section header table + EC = object_error::parse_failed; + } return; } diff --git a/test/Object/invalid.test b/test/Object/invalid.test index dd431aa3a55..057239de991 100644 --- a/test/Object/invalid.test +++ b/test/Object/invalid.test @@ -57,7 +57,7 @@ RUN: not llvm-readobj -t %p/Inputs/invalid-xindex-size.elf 2>&1 | FileCheck --ch INVALID-XINDEX-SIZE: Invalid data was encountered while parsing the file. RUN: not llvm-readobj -t %p/Inputs/invalid-e_shnum.elf 2>&1 | FileCheck --check-prefix=INVALID-SH-NUM %s -INVALID-SH-NUM: e_shnum should be zero if a file has no section header table +INVALID-SH-NUM: Invalid data was encountered while parsing the file. RUN: not llvm-readobj -t %p/Inputs/invalid-ext-symtab-index.elf-x86-64 2>&1 | \ RUN: FileCheck --check-prefix=INVALID-EXT-SYMTAB-INDEX %s