From 3848c2a0184d029d6be24a743216e0279fbda8e1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 15 Jan 2017 12:16:36 -0500 Subject: [PATCH] MemoryView: Get rid of a type-punning cast from u32 to float This is undefined behavior. The bits should be memcpyed. --- Source/Core/DolphinWX/Debugger/MemoryView.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Core/DolphinWX/Debugger/MemoryView.cpp b/Source/Core/DolphinWX/Debugger/MemoryView.cpp index 5f6abb30ae..5265058562 100644 --- a/Source/Core/DolphinWX/Debugger/MemoryView.cpp +++ b/Source/Core/DolphinWX/Debugger/MemoryView.cpp @@ -2,9 +2,12 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "DolphinWX/Debugger/MemoryView.h" + #include #include #include +#include #include #include #include @@ -24,7 +27,6 @@ #include "Core/PowerPC/PowerPC.h" #include "DolphinWX/Debugger/CodeWindow.h" #include "DolphinWX/Debugger/DebuggerUIUtil.h" -#include "DolphinWX/Debugger/MemoryView.h" #include "DolphinWX/Debugger/WatchWindow.h" #include "DolphinWX/Frame.h" #include "DolphinWX/Globals.h" @@ -112,8 +114,9 @@ wxString CMemoryView::ReadMemoryAsString(u32 address) const if (m_data_type == MemoryDataType::FloatingPoint) { - float& flt = reinterpret_cast(mem_data); - str = StringFromFormat("f: %f", flt); + float real; + std::memcpy(&real, &mem_data, sizeof(u32)); + str = StringFromFormat("f: %f", real); } else if (m_data_type == MemoryDataType::ASCII) {