mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									5ac4636a14
								
							
						
					
					
						commit
						41b7df4a32
					
				
					 1 changed files with 6 additions and 2 deletions
				
			
		|  | @ -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); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue