1
0
mirror of synced 2025-02-23 21:23:30 +01:00

fix: Diff view highlighting issues

This commit is contained in:
WerWolv 2023-01-30 10:26:37 +01:00
parent d6bb408078
commit 6b645192d4
2 changed files with 10 additions and 6 deletions

View File

@ -57,7 +57,7 @@ namespace hex::plugin::builtin {
}
void FileProvider::readRaw(u64 offset, void *buffer, size_t size) {
if ((offset + size) > this->getActualSize() || buffer == nullptr || size == 0)
if (offset > (this->getActualSize() - size) || buffer == nullptr || size == 0)
return;
std::memcpy(buffer, reinterpret_cast<u8 *>(this->m_mappedFile) + offset, size);

View File

@ -78,7 +78,7 @@ namespace hex::plugin::builtin {
};
struct LineInfo {
std::vector<u8> bytes;
i64 validBytes = 0;
u64 validBytes = 0;
};
static DiffResult diffBytes(u8 index, const LineInfo &a, const LineInfo &b) {
@ -105,9 +105,13 @@ namespace hex::plugin::builtin {
auto &provider = ImHexApi::Provider::getProviders()[id];
// Read one line of each provider
lineInfo[i].bytes.resize(this->m_columnCount);
lineInfo[i].validBytes = std::min<i64>(this->m_columnCount, provider->getSize() - row * this->m_columnCount);
provider->read(row * this->m_columnCount, lineInfo[i].bytes.data(), lineInfo[i].validBytes);
if (row * this->m_columnCount >= provider->getSize())
lineInfo[i].validBytes = 0;
else
lineInfo[i].validBytes = std::min<u64>(this->m_columnCount, provider->getSize() - row * this->m_columnCount);
lineInfo[i].bytes.resize(lineInfo[i].validBytes);
provider->read(provider->getBaseAddress() + provider->getCurrentPageAddress() + row * this->m_columnCount, lineInfo[i].bytes.data(), lineInfo[i].validBytes);
// Calculate address width
u8 addressDigits = 0;
@ -139,7 +143,7 @@ namespace hex::plugin::builtin {
bool hasLastHighlight = false;
ImVec2 lastHighlightEnd = { };
for (i64 col = 0; col < lineInfo[curr].validBytes; col++) {
for (u64 col = 0; col < lineInfo[curr].validBytes; col++) {
auto pos = ImGui::GetCursorScreenPos();
// Diff bytes