Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
DirtyHairy committed Jul 7, 2024
1 parent dce2123 commit 7386424
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/emucore/elf/ElfParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ void ElfParser::parse(const uInt8 *elfData, size_t size)
this->size = size;

sections.resize(0);
symbols.resize(0);
relocations.clear();
bigEndian = true;

try {
if (read32(0x00) != ELF_MAGIC) EInvalidElf::raise("bad magic");
Expand Down Expand Up @@ -68,9 +71,10 @@ void ElfParser::parse(const uInt8 *elfData, size_t size)
if (section.info >= sections.size()) EInvalidElf::raise("relocation table for invalid section");

vector<Relocation> rels;
rels.reserve(section.size / (section.type == SHT_REL ? REL_ENTRY_SIZE : RELA_ENTRY_SIZE));
const size_t relocationCount = section.size / (section.type == SHT_REL ? REL_ENTRY_SIZE : RELA_ENTRY_SIZE);
rels.reserve(section.size / relocationCount);

for (size_t i = 0; i < rels.capacity(); i++) {
for (size_t i = 0; i < relocationCount; i++) {
Relocation rel = readRelocation(i, section);

if (rel.symbol >= symbols.size()) EInvalidElf::raise("invalid relocation symbol");
Expand Down
6 changes: 6 additions & 0 deletions src/emucore/elf/ElfParser.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ class ElfParser {
vector<Section> sections;
vector<Symbol> symbols;
std::unordered_map<size_t, vector<Relocation>> relocations;

private:
ElfParser(const ElfParser&) = delete;
ElfParser(ElfParser&&) = delete;
ElfParser& operator=(const ElfParser&) = delete;
ElfParser& operator=(ElfParser&&) = delete;
};

ostream& operator<<(ostream& os, const ElfParser::Section& section);
Expand Down

0 comments on commit 7386424

Please sign in to comment.