sdl2-compat: fix integer overflow ub in testautomation_sdltest

From fbbb14acca6fa630fb955856dbeb5b0e0a1c93b8 Mon Sep 17 00:00:00 2001
From: Erica Z <[EMAIL REDACTED]>
Date: Mon, 6 Jan 2025 16:01:53 +0100
Subject: [PATCH] fix integer overflow ub in testautomation_sdltest

this replaces an instance of LONG_MAX + RandomSint16(), which is
undefined behavior when the random integer is positive, with LONG_MIN +
RandomUint16(). similarly, LONG_MIN - RandomSint16() is replaced with
LONG_MAX - RandomUint16().
---
 test/testautomation_sdltest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/testautomation_sdltest.c b/test/testautomation_sdltest.c
index 194a69d..23ef7df 100644
--- a/test/testautomation_sdltest.c
+++ b/test/testautomation_sdltest.c
@@ -1074,13 +1074,13 @@ int sdltest_randomIntegerInRange(void *arg)
 
     /* Range with min at integer limit */
     min = long_min;
-    max = long_max + (Sint32)SDLTest_RandomSint16();
+    max = long_min + (Sint32)SDLTest_RandomUint16();
     result = SDLTest_RandomIntegerInRange(min, max);
     SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(SINT32_MIN,...)");
     SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%" SDL_PRIs32 ",%" SDL_PRIs32 "], got: %" SDL_PRIs32, min, max, result);
 
     /* Range with max at integer limit */
-    min = long_min - (Sint32)SDLTest_RandomSint16();
+    min = long_max - (Sint32)SDLTest_RandomUint16();
     max = long_max;
     result = SDLTest_RandomIntegerInRange(min, max);
     SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(...,SINT32_MAX)");