From e5ff04be29f9229ecc2de0d9898dfd6c42453d86 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 8 Nov 2023 11:54:03 +0100 Subject: [PATCH] fix: Crash when using too large column count --- plugins/builtin/source/ui/hex_editor.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/builtin/source/ui/hex_editor.cpp b/plugins/builtin/source/ui/hex_editor.cpp index 244203965..c6425f445 100644 --- a/plugins/builtin/source/ui/hex_editor.cpp +++ b/plugins/builtin/source/ui/hex_editor.cpp @@ -278,10 +278,16 @@ namespace hex::plugin::builtin::ui { const auto bytesPerCell = this->m_currDataVisualizer->getBytesPerCell(); const u16 columnCount = this->m_bytesPerRow / bytesPerCell; - const auto byteColumnCount = columnCount + getByteColumnSeparatorCount(columnCount); + auto byteColumnCount = 2 + columnCount + getByteColumnSeparatorCount(columnCount) + 2 + 2; + + if (byteColumnCount >= IMGUI_TABLE_MAX_COLUMNS) { + this->m_bytesPerRow = 64; + ContentRegistry::Settings::write("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.bytes_per_row", this->m_bytesPerRow); + return; + } ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(0.5, 0)); - if (ImGui::BeginTable("##hex", 2 + byteColumnCount + 2 + 2 , ImGuiTableFlags_ScrollY | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoKeepColumnsVisible, size)) { + if (ImGui::BeginTable("##hex", byteColumnCount, ImGuiTableFlags_ScrollY | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoKeepColumnsVisible, size)) { View::discardNavigationRequests(); ImGui::TableSetupScrollFreeze(0, 2);