[llvm] r285738 - Use the existing std::error_code out parameter.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 1 13:24:22 PDT 2016


Author: rafael
Date: Tue Nov  1 15:24:22 2016
New Revision: 285738

URL: http://llvm.org/viewvc/llvm-project?rev=285738&view=rev
Log:
Use the existing std::error_code out parameter.

This avoids calling exit with a partially constructed object.

Modified:
    llvm/trunk/include/llvm/Object/ELF.h
    llvm/trunk/test/Object/invalid.test

Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=285738&r1=285737&r2=285738&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Tue Nov  1 15:24:22 2016
@@ -324,9 +324,10 @@ ELFFile<ELFT>::ELFFile(StringRef Object,
   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;
   }
 

Modified: llvm/trunk/test/Object/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/invalid.test?rev=285738&r1=285737&r2=285738&view=diff
==============================================================================
--- llvm/trunk/test/Object/invalid.test (original)
+++ llvm/trunk/test/Object/invalid.test Tue Nov  1 15:24:22 2016
@@ -57,7 +57,7 @@ RUN: not llvm-readobj -t %p/Inputs/inval
 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




More information about the llvm-commits mailing list