From bf3fe1739309eefc5cef845e8b64dfc5a70f2bbb Mon Sep 17 00:00:00 2001 From: silverweed Date: Thu, 25 Jul 2024 10:53:34 +0200 Subject: [PATCH] fix UB in mem edit --- third_party/imgui_club/imgui_memory_editor.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/third_party/imgui_club/imgui_memory_editor.h b/third_party/imgui_club/imgui_memory_editor.h index d9be5b7..466c3e6 100644 --- a/third_party/imgui_club/imgui_memory_editor.h +++ b/third_party/imgui_club/imgui_memory_editor.h @@ -436,7 +436,11 @@ struct MemoryEditor ImGui::SameLine(s.PosAsciiStart); ImVec2 pos = ImGui::GetCursorScreenPos(); addr = (size_t)line_i * Cols; - size_t mouseAddr = addr + (size_t)((ImGui::GetIO().MousePos.x - pos.x) / s.GlyphWidth); + float mposx = ImGui::GetIO().MousePos.x; + float posdiff = mposx - pos.x; + if (posdiff < 0) + posdiff = 0; + size_t mouseAddr = addr + (size_t)(posdiff / s.GlyphWidth); ImGui::PushID(line_i); if (ImGui::InvisibleButton("ascii", ImVec2(s.PosAsciiEnd - s.PosAsciiStart, s.LineHeight))) {