Convert an assert that can fail into error checking.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240944 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2015-06-29 14:02:24 +00:00
parent e8f07a7eb3
commit db89b93b44
3 changed files with 3 additions and 1 deletions

View File

@@ -867,7 +867,8 @@ ELFFile<ELFT>::getSection(uint32_t index) const {
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);