From 05b45da6291e3ccd1320454ea469fd335a373f8c Mon Sep 17 00:00:00 2001 From: Stefano Zanotti <7887495+stefano-zanotti-88@users.noreply.github.com> Date: Wed, 27 Jun 2018 10:37:00 +0200 Subject: [PATCH] stb_sprintf: fix unaligned access Fix an unaligned 32-bit access even if STB_SPRINTF_NOUNALIGNED was defined. --- stb_sprintf.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/stb_sprintf.h b/stb_sprintf.h index 0ad26b2..f63e3ea 100644 --- a/stb_sprintf.h +++ b/stb_sprintf.h @@ -332,7 +332,17 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, if (callback) if ((STB_SPRINTF_MIN - (int)(bf - buf)) < 4) goto schk1; - *(stbsp__uint32 *)bf = v; + #ifdef STB_SPRINTF_NOUNALIGNED + if(((stbsp__uintptr)bf) & 3) { + bf[0] = f[0]; + bf[1] = f[1]; + bf[2] = f[2]; + bf[3] = f[3]; + } else + #endif + { + *(stbsp__uint32 *)bf = v; + } bf += 4; f += 4; }