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.
This commit is contained in:
Lioncash 2020-04-18 21:00:13 -04:00
parent 5ac4636a14
commit 41b7df4a32
1 changed files with 6 additions and 2 deletions

View File

@ -4,6 +4,7 @@
#include <array>
#include <cstddef>
#include <cstring>
#include <memory>
#include <utility>
#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);