From 38e0c9366e4a72c749ff0bcdf911d1fe9bdfe9f5 Mon Sep 17 00:00:00 2001 From: skywind3000 Date: Fri, 24 Apr 2020 17:05:43 +0800 Subject: [PATCH] take care of strict aliasing --- ikcp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ikcp.c b/ikcp.c index a96a9ee..c16680a 100644 --- a/ikcp.c +++ b/ikcp.c @@ -71,7 +71,7 @@ static inline char *ikcp_encode16u(char *p, unsigned short w) *(unsigned char*)(p + 0) = (w & 255); *(unsigned char*)(p + 1) = (w >> 8); #else - *(unsigned short*)(p) = w; + memcpy(p, &w, 2); #endif p += 2; return p; @@ -84,7 +84,7 @@ static inline const char *ikcp_decode16u(const char *p, unsigned short *w) *w = *(const unsigned char*)(p + 1); *w = *(const unsigned char*)(p + 0) + (*w << 8); #else - *w = *(const unsigned short*)p; + memcpy(w, p, 2); #endif p += 2; return p; @@ -99,7 +99,7 @@ static inline char *ikcp_encode32u(char *p, IUINT32 l) *(unsigned char*)(p + 2) = (unsigned char)((l >> 16) & 0xff); *(unsigned char*)(p + 3) = (unsigned char)((l >> 24) & 0xff); #else - *(IUINT32*)p = l; + memcpy(p, &l, 4); #endif p += 4; return p; @@ -114,7 +114,7 @@ static inline const char *ikcp_decode32u(const char *p, IUINT32 *l) *l = *(const unsigned char*)(p + 1) + (*l << 8); *l = *(const unsigned char*)(p + 0) + (*l << 8); #else - *l = *(const IUINT32*)p; + memcpy(l, p, 4); #endif p += 4; return p;