From 81e0be856a6273c414c456a64fd28879fe81bf45 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 24 Jan 2024 14:27:43 +0100 Subject: [PATCH] Fixed strict-aliasing violation in FormatTextureIDForDebugDisplay(). (#7090, #7256) --- imgui.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 75050e355..4cb27b555 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -14787,10 +14787,12 @@ void ImGui::DebugNodeColumns(ImGuiOldColumns* columns) static void FormatTextureIDForDebugDisplay(char* buf, int buf_size, ImTextureID tex_id) { + union { void* ptr; int integer; } tex_id_opaque; + memcpy(&tex_id_opaque, &tex_id, ImMin(sizeof(void*), sizeof(tex_id))); if (sizeof(tex_id) >= sizeof(void*)) - ImFormatString(buf, buf_size, "0x%p", (void*)*(intptr_t*)(void*)&tex_id); + ImFormatString(buf, buf_size, "0x%p", tex_id_opaque.ptr); else - ImFormatString(buf, buf_size, "0x%04X", *(int*)(void*)&tex_id); + ImFormatString(buf, buf_size, "0x%04X", tex_id_opaque.integer); } // [DEBUG] Display contents of ImDrawList