From 162e16fd8ef1d52652552b55184c62f7a801d263 Mon Sep 17 00:00:00 2001 From: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com> Date: Fri, 25 Dec 2020 16:23:40 +0100 Subject: [PATCH] Use memcpy to save and read savebuf --- src/core/common.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/common.h b/src/core/common.h index 7a578758..ff1e3b90 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -446,7 +446,8 @@ inline void SkipSaveBuf(uint8 *&buf, int32 skip) template inline const T ReadSaveBuf(uint8 *&buf) { - T &value = *(T*)buf; + T value; + memcpy(&value, buf, sizeof(T)); SkipSaveBuf(buf, sizeof(T)); return value; } @@ -454,10 +455,10 @@ inline const T ReadSaveBuf(uint8 *&buf) template inline T *WriteSaveBuf(uint8 *&buf, const T &value) { - T *p = (T*)buf; - *p = value; + memcpy(buf, &value, sizeof(T)); + T* result = (T*)buf; SkipSaveBuf(buf, sizeof(T)); - return p; + return result; }