From f5094be2852be3a3dbd177e03123eb3409ad26b4 Mon Sep 17 00:00:00 2001 From: pmttavara <34119228+pmttavara@users.noreply.github.com> Date: Wed, 14 Feb 2018 22:35:01 -0500 Subject: [PATCH] Prevent dangerous bug In the non-x86 version of memcopy, the lack of braces made seemingly conditional statements run unconditionally, potentially causing segfaults. --- gb.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gb.h b/gb.h index 0bf8909..db4de72 100644 --- a/gb.h +++ b/gb.h @@ -3798,12 +3798,15 @@ gb_inline void *gb_memcopy(void *dest, void const *source, isize n) { *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; } - if (n & 4) + if (n & 4) { *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - if (n & 2) + } + if (n & 2) { *d++ = *s++; *d++ = *s++; - if (n & 1) + } + if (n & 1) { *d = *s; + } } #endif