Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/SafeFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <common/Format.h> // Needed for CFormat
#include "CompilerSpecific.h" // Needed for __FUNCTION__

#include <cstring> // For std::memcpy

#define CHECK_BOM(size, x) ((size >= 3) && (x[0] == (char)0xEF) && (x[1] == (char)0xBB) && (x[2] == (char)0xBF))

Expand Down Expand Up @@ -189,6 +190,10 @@ float CFileDataIO::ReadFloat() const
{
float retVal;
Read(&retVal, sizeof(float));
uint32_t toswap{};
std::memcpy(&toswap, &retVal, sizeof(toswap));
toswap = ENDIAN_SWAP_32(toswap);
std::memcpy(&retVal, &toswap, sizeof(retVal));
return retVal;
}

Expand Down Expand Up @@ -306,6 +311,10 @@ void CFileDataIO::WriteHash(const CMD4Hash& value)

void CFileDataIO::WriteFloat(float value)
{
uint32_t toswap{};
std::memcpy(&toswap, &value, sizeof(toswap));
toswap = ENDIAN_SWAP_32(toswap);
std::memcpy(&value, &toswap, sizeof(value));
Write(&value, sizeof(float));
}

Expand Down