From 41b7df4a32ebb1dc44d96ecdebe545069f98c639 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 18 Apr 2020 21:00:13 -0400 Subject: [PATCH] command_processor: Resolve undefined behavior type punning We can use std::memcpy to achieve the same behavior without undefined behavior. Once Citra moves to C++20 we can convert this over to std::bit_cast. --- src/video_core/command_processor.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp index 7c5b1c4e59..e3b1360915 100644 --- a/src/video_core/command_processor.cpp +++ b/src/video_core/command_processor.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include "common/assert.h" @@ -86,8 +87,11 @@ static void WriteUniformFloatReg(ShaderRegs& config, Shader::ShaderSetup& setup, // NOTE: The destination component order indeed is "backwards" if (uniform_setup.IsFloat32()) { - for (auto i : {0, 1, 2, 3}) - uniform[3 - i] = float24::FromFloat32(*(float*)(&uniform_write_buffer[i])); + for (auto i : {0, 1, 2, 3}) { + float buffer_value; + std::memcpy(&buffer_value, &uniform_write_buffer[i], sizeof(float)); + uniform[3 - i] = float24::FromFloat32(buffer_value); + } } else { // TODO: Untested uniform.w = float24::FromRaw(uniform_write_buffer[0] >> 8);