From 7386424ccc5c9675845477d6f4bda560ae5c6a70 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sun, 7 Jul 2024 09:25:37 +0200 Subject: [PATCH] Cleanup. --- src/emucore/elf/ElfParser.cxx | 8 ++++++-- src/emucore/elf/ElfParser.hxx | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/emucore/elf/ElfParser.cxx b/src/emucore/elf/ElfParser.cxx index 109ed3291..c471d4789 100644 --- a/src/emucore/elf/ElfParser.cxx +++ b/src/emucore/elf/ElfParser.cxx @@ -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"); @@ -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 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"); diff --git a/src/emucore/elf/ElfParser.hxx b/src/emucore/elf/ElfParser.hxx index ca243b100..f757ac77b 100644 --- a/src/emucore/elf/ElfParser.hxx +++ b/src/emucore/elf/ElfParser.hxx @@ -150,6 +150,12 @@ class ElfParser { vector
sections; vector symbols; std::unordered_map> 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);