fix: BufferedReader messing up the second to last byte

This commit is contained in:
WerWolv 2022-09-16 08:30:28 +02:00
parent 44a90f5c7d
commit bf00503d1f
2 changed files with 6 additions and 3 deletions

View File

@ -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

View File

@ -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;