]> granicus.if.org Git - llvm/commitdiff
Use the existing std::error_code out parameter.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 1 Nov 2016 20:24:22 +0000 (20:24 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 1 Nov 2016 20:24:22 +0000 (20:24 +0000)
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

include/llvm/Object/ELF.h
test/Object/invalid.test

index 2c715bffa2fdfc9922c1c05e7d07422c8a72b28a..10f61ad2f285fd51e14bd9f30f9bed5197d955ca 100644 (file)
@@ -324,9 +324,10 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
   Header = reinterpret_cast<const Elf_Ehdr *>(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;
   }
 
index dd431aa3a55e41acacaddb266888d03402a2336d..057239de9914fcfc32f73825d31d16cc1481ca1f 100644 (file)
@@ -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