Convert getSymbolSection to return an ErrorOr.

This function can actually fail since the symbol contains an index to the
section and that can be invalid.

llvm-svn: 244375
This commit is contained in:
Rafael Espindola
2015-08-07 23:27:14 +00:00
parent eeebc41b58
commit 8bab889b0f
22 changed files with 83 additions and 91 deletions

View File

@@ -445,22 +445,18 @@ uint32_t MachOObjectFile::getSymbolFlags(DataRefImpl DRI) const {
return Result;
}
std::error_code MachOObjectFile::getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const {
ErrorOr<section_iterator>
MachOObjectFile::getSymbolSection(DataRefImpl Symb) const {
MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
uint8_t index = Entry.n_sect;
if (index == 0) {
Res = section_end();
} else {
DataRefImpl DRI;
DRI.d.a = index - 1;
if (DRI.d.a >= Sections.size())
report_fatal_error("getSymbolSection: Invalid section index.");
Res = section_iterator(SectionRef(DRI, this));
}
return std::error_code();
if (index == 0)
return section_end();
DataRefImpl DRI;
DRI.d.a = index - 1;
if (DRI.d.a >= Sections.size())
report_fatal_error("getSymbolSection: Invalid section index.");
return section_iterator(SectionRef(DRI, this));
}
unsigned MachOObjectFile::getSymbolSectionID(SymbolRef Sym) const {