Commit 5bfdb6e02fa6554b92367f34d9fc324e2ff9be5a

Anonymous Maarten 2023-08-10T23:43:58

Fix overflow when doing SDL_sscanf("%hd", ...) An overflow occured in the stdlib_sscanf test, when using msys2 clang32 toolchain. (cherry picked from commit 342ec5113171214154cb197bb3e0e3a0056ea2ad) (cherry picked from commit 10135b2d7bbed6ea0cba24410ebc12887d92968d)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c
index 616e3e1..09c4489 100644
--- a/src/stdlib/SDL_string.c
+++ b/src/stdlib/SDL_string.c
@@ -1190,7 +1190,9 @@ int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
                     suppress = SDL_TRUE;
                     break;
                 case 'h':
-                    if (inttype > DO_SHORT) {
+                    if (inttype == DO_INT) {
+                        inttype = DO_SHORT;
+                    } else if (inttype > DO_SHORT) {
                         ++inttype;
                     }
                     break;