From 4b720ee3a24e57ab8745db8dd99343fd247ea466 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 9 Aug 2022 15:00:31 +0200 Subject: [PATCH] fix: More crashes with multi-byte visualizers --- .../builtin/source/content/views/view_hex_editor.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 7d20481d4..b66dc66bc 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -745,7 +745,7 @@ namespace hex::plugin::builtin { const u8 validBytes = std::min(this->m_bytesPerRow, provider->getSize() - y * this->m_bytesPerRow); - std::vector bytes(validBytes); + std::vector bytes(this->m_bytesPerRow, 0x00); provider->read(y * this->m_bytesPerRow + provider->getBaseAddress() + provider->getCurrentPageAddress(), bytes.data(), validBytes); std::vector, std::optional>> cellColors; @@ -756,7 +756,7 @@ namespace hex::plugin::builtin { const auto cellBytes = std::min(validBytes, bytesPerCell); // Query cell colors - if (x < validBytes / bytesPerCell) { + if (x < std::ceil(float(validBytes) / bytesPerCell)) { const auto foregroundColor = queryForegroundColor(byteAddress, &bytes[x * cellBytes], cellBytes); const auto backgroundColor = [&]{ auto color = queryBackgroundColor(byteAddress, &bytes[x * cellBytes], cellBytes); @@ -778,6 +778,11 @@ namespace hex::plugin::builtin { foregroundColor, backgroundColor ); + } else { + cellColors.emplace_back( + std::nullopt, + std::nullopt + ); } } } @@ -792,7 +797,7 @@ namespace hex::plugin::builtin { if (isColumnSeparatorColumn(x, columnCount)) ImGui::TableNextColumn(); - if (x < validBytes / bytesPerCell) { + if (x < std::ceil(float(validBytes) / bytesPerCell)) { auto cellStartPos = getCellPosition(); auto cellSize = (CharacterSize * ImVec2(this->m_currDataVisualizer->getMaxCharsPerCell(), 1) + (ImVec2(3, 2) * ImGui::GetStyle().CellPadding) - ImVec2(1, 0) * ImGui::GetStyle().CellPadding) + ImVec2(1, 0);