Use memcpy for reading and writing SaveBufs

This commit is contained in:
GaryOderNichts 2021-08-21 17:28:31 +02:00
parent 58e725bd03
commit ec1f0f4c93

View File

@ -32,7 +32,7 @@ template<typename T>
inline void inline void
ReadSaveBuf(T *out, uint8 *&buf) ReadSaveBuf(T *out, uint8 *&buf)
{ {
*out = *(T *)buf; memcpy(out, buf, sizeof(T));
SkipSaveBuf(buf, sizeof(T)); SkipSaveBuf(buf, sizeof(T));
} }
@ -40,7 +40,7 @@ template<typename T>
inline void inline void
ReadSaveBuf(T *out, uint8 *&buf, uint32 &length) ReadSaveBuf(T *out, uint8 *&buf, uint32 &length)
{ {
*out = *(T *)buf; memcpy(out, buf, sizeof(T));
SkipSaveBuf(buf, length, sizeof(T)); SkipSaveBuf(buf, length, sizeof(T));
} }
@ -48,8 +48,8 @@ template<typename T>
inline T * inline T *
WriteSaveBuf(uint8 *&buf, const T &value) WriteSaveBuf(uint8 *&buf, const T &value)
{ {
memcpy(buf, &value, sizeof(T));
T* p = (T*)buf; T* p = (T*)buf;
*p = value;
SkipSaveBuf(buf, sizeof(T)); SkipSaveBuf(buf, sizeof(T));
return p; return p;
} }
@ -58,8 +58,8 @@ template<typename T>
inline T * inline T *
WriteSaveBuf(uint8 *&buf, uint32 &length, const T &value) WriteSaveBuf(uint8 *&buf, uint32 &length, const T &value)
{ {
memcpy(buf, &value, sizeof(T));
T* p = (T*)buf; T* p = (T*)buf;
*p = value;
SkipSaveBuf(buf, length, sizeof(T)); SkipSaveBuf(buf, length, sizeof(T));
return p; return p;
} }