Use memcpy to save and read savebuf

This commit is contained in:
GaryOderNichts 2020-12-25 16:23:40 +01:00
parent a01a53e697
commit 162e16fd8e

View File

@ -446,7 +446,8 @@ inline void SkipSaveBuf(uint8 *&buf, int32 skip)
template<typename T> template<typename T>
inline const T ReadSaveBuf(uint8 *&buf) inline const T ReadSaveBuf(uint8 *&buf)
{ {
T &value = *(T*)buf; T value;
memcpy(&value, buf, sizeof(T));
SkipSaveBuf(buf, sizeof(T)); SkipSaveBuf(buf, sizeof(T));
return value; return value;
} }
@ -454,10 +455,10 @@ inline const T ReadSaveBuf(uint8 *&buf)
template<typename T> template<typename T>
inline T *WriteSaveBuf(uint8 *&buf, const T &value) inline T *WriteSaveBuf(uint8 *&buf, const T &value)
{ {
T *p = (T*)buf; memcpy(buf, &value, sizeof(T));
*p = value; T* result = (T*)buf;
SkipSaveBuf(buf, sizeof(T)); SkipSaveBuf(buf, sizeof(T));
return p; return result;
} }