Commit ab6d0d4d509ec0d5a60f01a59216e9cf87edd67c

Sam Lantinga 2021-12-28T15:58:15

Fixed undefined behavior in SDL_memset() (thanks andrewrk!) Fixes https://github.com/libsdl-org/SDL/issues/5147

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c
index 8f2aade..0fe0875 100644
--- a/src/stdlib/SDL_string.c
+++ b/src/stdlib/SDL_string.c
@@ -295,7 +295,7 @@ SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
         }
     }
 
-    value4 = (c | (c << 8) | (c << 16) | (c << 24));
+    value4 = ((Uint32)c | ((Uint32)c << 8) | ((Uint32)c << 16) | ((Uint32)c << 24));
     dstp4 = (Uint32 *) dstp1;
     left = (len % 4);
     len /= 4;