Skip to content

Commit

Permalink
fix integer overflow ub in testautomation_sdltest
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
z-erica committed Jan 6, 2025
1 parent 3ca00c9 commit f6222d6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/testautomation_sdltest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down

0 comments on commit f6222d6

Please sign in to comment.