1
0
mirror of synced 2024-11-28 09:30:51 +01:00

fix: Buffered reader returning zeros if provider size is below 16MiB

Fixes #707
This commit is contained in:
WerWolv 2022-08-29 16:32:32 +02:00
parent b687eb88f9
commit 3cb6c4f775

View File

@ -4,14 +4,17 @@
#include <vector>
#include <hex/providers/provider.hpp>
#include <hex/helpers/literals.hpp>
namespace hex::prv {
using namespace hex::literals;
class BufferedReader {
public:
explicit BufferedReader(Provider *provider, size_t bufferSize = 0xFF'FFFF)
explicit BufferedReader(Provider *provider, size_t bufferSize = 16_MiB)
: m_provider(provider), m_bufferAddress(provider->getBaseAddress()), m_maxBufferSize(bufferSize),
m_startAddress(0x00), m_endAddress(provider->getActualSize()),
m_startAddress(0x00), m_endAddress(provider->getActualSize() - 1),
m_buffer(bufferSize) {
}
@ -253,9 +256,11 @@ 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
this->m_buffer.resize(this->m_maxBufferSize);
this->m_provider->read(address, this->m_buffer.data(), this->m_buffer.size());
this->m_bufferAddress = address;