From bf00503d1f0013929c2b6e881309816f3dea75e7 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 16 Sep 2022 08:30:28 +0200 Subject: [PATCH] fix: BufferedReader messing up the second to last byte --- lib/libimhex/include/hex/providers/buffered_reader.hpp | 5 ++++- plugins/builtin/source/content/data_formatters.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/libimhex/include/hex/providers/buffered_reader.hpp b/lib/libimhex/include/hex/providers/buffered_reader.hpp index 1a32c49c9..b46076b18 100644 --- a/lib/libimhex/include/hex/providers/buffered_reader.hpp +++ b/lib/libimhex/include/hex/providers/buffered_reader.hpp @@ -24,6 +24,9 @@ namespace hex::prv { } void setEndAddress(u64 address) { + if (address >= this->m_provider->getActualSize()) + address = this->m_provider->getActualSize() - 1; + this->m_endAddress = address; } @@ -256,7 +259,7 @@ namespace hex::prv { private: void updateBuffer(u64 address, size_t size) { if (!this->m_bufferValid || address < this->m_bufferAddress || address + size > (this->m_bufferAddress + this->m_buffer.size())) { - const auto remainingBytes = (this->m_endAddress - address) - 1; + const auto remainingBytes = (this->m_endAddress - address) + 1; if (remainingBytes < this->m_maxBufferSize) this->m_buffer.resize(remainingBytes); else diff --git a/plugins/builtin/source/content/data_formatters.cpp b/plugins/builtin/source/content/data_formatters.cpp index 3e0b560a8..6c314bc00 100644 --- a/plugins/builtin/source/content/data_formatters.cpp +++ b/plugins/builtin/source/content/data_formatters.cpp @@ -18,7 +18,7 @@ namespace hex::plugin::builtin { auto reader = prv::BufferedReader(provider); reader.seek(offset); - reader.setEndAddress(offset + size); + reader.setEndAddress(offset + size - 1); u64 index = 0x00; for (u8 byte : reader) { @@ -160,7 +160,7 @@ namespace hex::plugin::builtin { auto reader = prv::BufferedReader(provider); reader.seek(offset); - reader.setEndAddress(offset + size); + reader.setEndAddress((offset + size) - 1); u64 address = offset & ~u64(0x0F); std::string asciiRow;