Skip to content

Commit 231eb3f

Browse files
committed
More defensive access.
1 parent 8ab0133 commit 231eb3f

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

third_party/imgui_memory_editor/imgui_memory_editor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ void MemoryEditor::DrawPreviewLine(const Sizes& s, size_t mem_size)
460460

461461
char buf[128] = "";
462462
float x = s.GlyphWidth * 6.0f;
463-
bool has_value = DataPreviewAddr != (size_t)-1;
463+
bool has_value = DataPreviewAddr != (size_t)-1 && DataPreviewAddr < mem_size;
464464
if (has_value)
465465
DrawPreviewData(DataPreviewAddr, mem_size, PreviewDataType, DataFormat_Dec, buf, (size_t)IM_ARRAYSIZE(buf));
466466
ImGui::Text("Dec"); ImGui::SameLine(x); ImGui::TextUnformatted(has_value ? buf : "N/A");
@@ -563,6 +563,7 @@ const char* MemoryEditor::FormatBinary(const uint8_t* buf, int width) const
563563
// [Internal]
564564
void MemoryEditor::DrawPreviewData(size_t addr, size_t mem_size, ImGuiDataType data_type, DataFormat data_format, char* out_buf, size_t out_buf_size) const
565565
{
566+
if (addr >= mem_size) { out_buf[0] = 0; return; }
566567
uint8_t buf[8];
567568
size_t elem_size = DataTypeGetSize(data_type);
568569
size_t size = addr + elem_size > mem_size ? mem_size - addr : elem_size;

0 commit comments

Comments
 (0)