[llvm] r240944 - Convert an assert that can fail into error checking.

Rafael Espindola rafael.espindola at gmail.com
Mon Jun 29 07:02:25 PDT 2015


Author: rafael
Date: Mon Jun 29 09:02:24 2015
New Revision: 240944

URL: http://llvm.org/viewvc/llvm-project?rev=240944&view=rev
Log:
Convert an assert that can fail into error checking.

Added:
    llvm/trunk/test/Object/Inputs/invalid-strtab-type.elf
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=240944&r1=240943&r2=240944&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Mon Jun 29 09:02:24 2015
@@ -867,7 +867,8 @@ ELFFile<ELFT>::getSection(uint32_t index
 template <class ELFT>
 ErrorOr<StringRef> ELFFile<ELFT>::getString(const Elf_Shdr *Section,
                                             ELF::Elf32_Word Offset) const {
-  assert(Section && Section->sh_type == ELF::SHT_STRTAB && "Invalid section!");
+  if (Section->sh_type != ELF::SHT_STRTAB)
+    return object_error::parse_failed;
   if (Offset >= Section->sh_size)
     return object_error::parse_failed;
   return StringRef((const char *)base() + Section->sh_offset + Offset);

Added: llvm/trunk/test/Object/Inputs/invalid-strtab-type.elf
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/invalid-strtab-type.elf?rev=240944&view=auto
==============================================================================
Binary files llvm/trunk/test/Object/Inputs/invalid-strtab-type.elf (added) and llvm/trunk/test/Object/Inputs/invalid-strtab-type.elf Mon Jun 29 09:02:24 2015 differ

Modified: llvm/trunk/test/Object/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/invalid.test?rev=240944&r1=240943&r2=240944&view=diff
==============================================================================
--- llvm/trunk/test/Object/invalid.test (original)
+++ llvm/trunk/test/Object/invalid.test Mon Jun 29 09:02:24 2015
@@ -1,2 +1,3 @@
 RUN: not llvm-dwarfdump %p/Inputs/invalid-bad-rel-type.elf 2>&1 | FileCheck %s
+RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-type.elf 2>&1 | FileCheck %s
 CHECK: Invalid data was encountered while parsing the file





More information about the llvm-commits mailing list