update sdl to 2.32.6

This commit is contained in:
AzaezelX 2025-05-24 13:39:03 -05:00
parent e557f5962b
commit ddc1f8c1e2
1339 changed files with 53966 additions and 19207 deletions

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -107,7 +107,7 @@ void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,
/*
* Resets the assert summary counters to zero.
*/
void SDLTest_ResetAssertSummary()
void SDLTest_ResetAssertSummary(void)
{
SDLTest_AssertsPassed = 0;
SDLTest_AssertsFailed = 0;
@ -117,7 +117,7 @@ void SDLTest_ResetAssertSummary()
* Logs summary of all assertions (total, pass, fail) since last reset
* as INFO (failed==0) or ERROR (failed > 0).
*/
void SDLTest_LogAssertSummary()
void SDLTest_LogAssertSummary(void)
{
int totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed;
if (SDLTest_AssertsFailed == 0) {
@ -130,7 +130,7 @@ void SDLTest_LogAssertSummary()
/*
* Converts the current assert state into a test result
*/
int SDLTest_AssertSummaryToTestResult()
int SDLTest_AssertSummaryToTestResult(void)
{
if (SDLTest_AssertsFailed > 0) {
return TEST_RESULT_FAILED;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -72,7 +72,7 @@ SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, Uint32 flags)
}
state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state));
if (state == NULL) {
if (!state) {
SDL_OutOfMemory();
return NULL;
}
@ -134,6 +134,7 @@ int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
return -1;
}
state->videodriver = argv[index];
SDL_SetHint(SDL_HINT_VIDEODRIVER, state->videodriver);
return 2;
}
if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
@ -591,7 +592,7 @@ void SDLTest_CommonLogUsage(SDLTest_CommonState *state, const char *argv0, const
static const char *BuildCommonUsageString(char **pstr, const char **strlist, const int numitems, const char **strlist2, const int numitems2)
{
char *str = *pstr;
if (str == NULL) {
if (!str) {
size_t len = SDL_strlen("[--trackmem]") + 2;
int i;
for (i = 0; i < numitems; i++) {
@ -603,7 +604,7 @@ static const char *BuildCommonUsageString(char **pstr, const char **strlist, con
}
}
str = (char *)SDL_calloc(1, len);
if (str == NULL) {
if (!str) {
return ""; /* oh well. */
}
SDL_strlcat(str, "[--trackmem] ", len);
@ -802,6 +803,82 @@ static void SDLTest_PrintWindowFlags(char *text, size_t maxlen, Uint32 flags)
}
}
static void SDLTest_PrintModStateFlag(char *text, size_t maxlen, SDL_Keymod flag)
{
switch (flag) {
case KMOD_LSHIFT:
SDL_snprintfcat(text, maxlen, "LSHIFT");
break;
case KMOD_RSHIFT:
SDL_snprintfcat(text, maxlen, "RSHIFT");
break;
case KMOD_LCTRL:
SDL_snprintfcat(text, maxlen, "LCTRL");
break;
case KMOD_RCTRL:
SDL_snprintfcat(text, maxlen, "RCTRL");
break;
case KMOD_LALT:
SDL_snprintfcat(text, maxlen, "LALT");
break;
case KMOD_RALT:
SDL_snprintfcat(text, maxlen, "RALT");
break;
case KMOD_LGUI:
SDL_snprintfcat(text, maxlen, "LGUI");
break;
case KMOD_RGUI:
SDL_snprintfcat(text, maxlen, "RGUI");
break;
case KMOD_NUM:
SDL_snprintfcat(text, maxlen, "NUM");
break;
case KMOD_CAPS:
SDL_snprintfcat(text, maxlen, "CAPS");
break;
case KMOD_MODE:
SDL_snprintfcat(text, maxlen, "MODE");
break;
case KMOD_SCROLL:
SDL_snprintfcat(text, maxlen, "SCROLL");
break;
default:
SDL_snprintfcat(text, maxlen, "0x%8.8x", (unsigned int) flag);
break;
}
}
static void SDLTest_PrintModState(char *text, size_t maxlen, SDL_Keymod keymod)
{
const SDL_Keymod kmod_flags[] = {
KMOD_LSHIFT,
KMOD_RSHIFT,
KMOD_LCTRL,
KMOD_RCTRL,
KMOD_LALT,
KMOD_RALT,
KMOD_LGUI,
KMOD_RGUI,
KMOD_NUM,
KMOD_CAPS,
KMOD_MODE,
KMOD_SCROLL
};
int i;
int count = 0;
for (i = 0; i < SDL_arraysize(kmod_flags); ++i) {
const SDL_Keymod flag = kmod_flags[i];
if ((keymod & flag) == flag) {
if (count > 0) {
SDL_snprintfcat(text, maxlen, " | ");
}
SDLTest_PrintModStateFlag(text, maxlen, flag);
++count;
}
}
}
static void SDLTest_PrintButtonMask(char *text, size_t maxlen, Uint32 flags)
{
int i;
@ -851,6 +928,12 @@ static void SDLTest_PrintPixelFormat(char *text, size_t maxlen, Uint32 format)
case SDL_PIXELFORMAT_INDEX1MSB:
SDL_snprintfcat(text, maxlen, "Index1MSB");
break;
case SDL_PIXELFORMAT_INDEX2LSB:
SDL_snprintfcat(text, maxlen, "Index2LSB");
break;
case SDL_PIXELFORMAT_INDEX2MSB:
SDL_snprintfcat(text, maxlen, "Index2MSB");
break;
case SDL_PIXELFORMAT_INDEX4LSB:
SDL_snprintfcat(text, maxlen, "Index4LSB");
break;
@ -991,7 +1074,7 @@ static SDL_Surface *SDLTest_LoadIcon(const char *file)
/* Load the icon surface */
icon = SDL_LoadBMP(file);
if (icon == NULL) {
if (!icon) {
SDL_Log("Couldn't load %s: %s\n", file, SDL_GetError());
return NULL;
}
@ -1120,7 +1203,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
SDL_DisplayMode mode;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
#if SDL_VIDEO_DRIVER_WINDOWS
#ifdef SDL_VIDEO_DRIVER_WINDOWS
int adapterIndex = 0;
int outputIndex = 0;
#endif
@ -1183,7 +1266,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
}
}
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#if defined(SDL_VIDEO_DRIVER_WINDOWS) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Print the D3D9 adapter index */
adapterIndex = SDL_Direct3D9GetAdapterIndex(i);
SDL_Log("D3D9 Adapter Index: %d", adapterIndex);
@ -1511,11 +1594,10 @@ static void SDLTest_PrintEvent(SDL_Event *event)
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " restored", event->window.windowID);
break;
case SDL_WINDOWEVENT_ENTER:
SDL_Log("SDL EVENT: Mouse entered window %" SDL_PRIu32 "",
event->window.windowID);
SDL_Log("SDL EVENT: Mouse entered window %" SDL_PRIu32, event->window.windowID);
break;
case SDL_WINDOWEVENT_LEAVE:
SDL_Log("SDL EVENT: Mouse left window %" SDL_PRIu32 "", event->window.windowID);
SDL_Log("SDL EVENT: Mouse left window %" SDL_PRIu32, event->window.windowID);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " gained keyboard focus",
@ -1538,7 +1620,7 @@ static void SDLTest_PrintEvent(SDL_Event *event)
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " ICC profile changed", event->window.windowID);
break;
case SDL_WINDOWEVENT_DISPLAY_CHANGED:
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " display changed to %" SDL_PRIs32 "", event->window.windowID, event->window.data1);
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " display changed to %" SDL_PRIs32, event->window.windowID, event->window.data1);
break;
default:
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " got unknown event 0x%4.4x",
@ -1547,19 +1629,23 @@ static void SDLTest_PrintEvent(SDL_Event *event)
}
break;
case SDL_KEYDOWN:
SDL_Log("SDL EVENT: Keyboard: key pressed in window %" SDL_PRIu32 ": scancode 0x%08X = %s, keycode 0x%08" SDL_PRIX32 " = %s",
case SDL_KEYUP: {
char modstr[64];
if (event->key.keysym.mod) {
modstr[0] = '\0';
SDLTest_PrintModState(modstr, sizeof (modstr), event->key.keysym.mod);
} else {
SDL_strlcpy(modstr, "NONE", sizeof (modstr));
}
SDL_Log("SDL EVENT: Keyboard: key %s in window %" SDL_PRIu32 ": scancode 0x%08X = %s, keycode 0x%08" SDL_PRIX32 " = %s, mods = %s",
(event->type == SDL_KEYDOWN) ? "pressed" : "released",
event->key.windowID,
event->key.keysym.scancode,
SDL_GetScancodeName(event->key.keysym.scancode),
event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
break;
case SDL_KEYUP:
SDL_Log("SDL EVENT: Keyboard: key released in window %" SDL_PRIu32 ": scancode 0x%08X = %s, keycode 0x%08" SDL_PRIX32 " = %s",
event->key.windowID,
event->key.keysym.scancode,
SDL_GetScancodeName(event->key.keysym.scancode),
event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym),
modstr);
break;
}
case SDL_TEXTEDITING:
SDL_Log("SDL EVENT: Keyboard: text editing \"%s\" in window %" SDL_PRIu32,
event->edit.text, event->edit.windowID);
@ -1756,7 +1842,7 @@ static void SDLTest_ScreenShot(SDL_Renderer *renderer)
SDL_Rect viewport;
SDL_Surface *surface;
if (renderer == NULL) {
if (!renderer) {
return;
}
@ -1768,7 +1854,7 @@ static void SDLTest_ScreenShot(SDL_Renderer *renderer)
0x000000FF, 0x0000FF00, 0x00FF0000,
#endif
0x00000000);
if (surface == NULL) {
if (!surface) {
SDL_Log("Couldn't create surface: %s\n", SDL_GetError());
return;
}
@ -1792,7 +1878,7 @@ static void FullscreenTo(int index, int windowId)
Uint32 flags;
struct SDL_Rect rect = { 0, 0, 0, 0 };
SDL_Window *window = SDL_GetWindowFromID(windowId);
if (window == NULL) {
if (!window) {
return;
}
@ -2394,6 +2480,19 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
SDLTest_DrawString(renderer, 0, textY, text);
textY += lineHeight;
/* Keyboard */
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDLTest_DrawString(renderer, 0, textY, "-- Keyboard --");
textY += lineHeight;
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
(void)SDL_snprintf(text, sizeof(text), "SDL_GetModState: ");
SDLTest_PrintModState(text, sizeof(text), SDL_GetModState());
SDLTest_DrawString(renderer, 0, textY, text);
textY += lineHeight;
if (usedHeight) {
*usedHeight = textY;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -70,7 +70,7 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface,
char referenceFilename[FILENAME_SIZE];
/* Validate input surfaces */
if (surface == NULL || referenceSurface == NULL) {
if (!surface || !referenceSurface) {
return -1;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -36,7 +36,7 @@ int SDLTest_Crc32Init(SDLTest_Crc32Context *crcContext)
CrcUint32 c;
/* Sanity check context pointer */
if (crcContext == NULL) {
if (!crcContext) {
return -1;
}
@ -90,7 +90,7 @@ int SDLTest_Crc32Calc(SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint
int SDLTest_Crc32CalcStart(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32)
{
/* Sanity check pointers */
if (crcContext == NULL) {
if (!crcContext) {
*crc32 = 0;
return -1;
}
@ -108,7 +108,7 @@ int SDLTest_Crc32CalcStart(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32)
int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32)
{
/* Sanity check pointers */
if (crcContext == NULL) {
if (!crcContext) {
*crc32 = 0;
return -1;
}
@ -128,12 +128,12 @@ int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, C
CrcUint8 *p;
register CrcUint32 crc;
if (crcContext == NULL) {
if (!crcContext) {
*crc32 = 0;
return -1;
}
if (inBuf == NULL) {
if (!inBuf) {
return -1;
}
@ -155,7 +155,7 @@ int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, C
int SDLTest_Crc32Done(SDLTest_Crc32Context *crcContext)
{
if (crcContext == NULL) {
if (!crcContext) {
return -1;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -3166,14 +3166,14 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c)
ci = c;
/* Search for this renderer's cache */
for (cache = SDLTest_CharTextureCacheList; cache != NULL; cache = cache->next) {
for (cache = SDLTest_CharTextureCacheList; cache; cache = cache->next) {
if (cache->renderer == renderer) {
break;
}
}
/* Allocate a new cache for this renderer if needed */
if (cache == NULL) {
if (!cache) {
cache = (struct SDLTest_CharTextureCache *)SDL_calloc(1, sizeof(struct SDLTest_CharTextureCache));
cache->renderer = renderer;
cache->next = SDLTest_CharTextureCacheList;
@ -3190,7 +3190,7 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c)
character = SDL_CreateRGBSurface(SDL_SWSURFACE,
charWidth, charHeight, 32,
0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
if (character == NULL) {
if (!character) {
return -1;
}
@ -3358,7 +3358,7 @@ SDLTest_TextWindow *SDLTest_TextWindowCreate(int x, int y, int w, int h)
{
SDLTest_TextWindow *textwin = (SDLTest_TextWindow *)SDL_malloc(sizeof(*textwin));
if (textwin == NULL) {
if (!textwin) {
return NULL;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -68,54 +68,54 @@ void SDLTest_FuzzerInit(Uint64 execKey)
fuzzerInvocationCounter = 0;
}
int SDLTest_GetFuzzerInvocationCount()
int SDLTest_GetFuzzerInvocationCount(void)
{
return fuzzerInvocationCounter;
}
Uint8 SDLTest_RandomUint8()
Uint8 SDLTest_RandomUint8(void)
{
fuzzerInvocationCounter++;
return (Uint8)SDLTest_RandomInt(&rndContext) & 0x000000FF;
}
Sint8 SDLTest_RandomSint8()
Sint8 SDLTest_RandomSint8(void)
{
fuzzerInvocationCounter++;
return (Sint8)SDLTest_RandomInt(&rndContext) & 0x000000FF;
}
Uint16 SDLTest_RandomUint16()
Uint16 SDLTest_RandomUint16(void)
{
fuzzerInvocationCounter++;
return (Uint16)SDLTest_RandomInt(&rndContext) & 0x0000FFFF;
}
Sint16 SDLTest_RandomSint16()
Sint16 SDLTest_RandomSint16(void)
{
fuzzerInvocationCounter++;
return (Sint16)SDLTest_RandomInt(&rndContext) & 0x0000FFFF;
}
Sint32 SDLTest_RandomSint32()
Sint32 SDLTest_RandomSint32(void)
{
fuzzerInvocationCounter++;
return (Sint32)SDLTest_RandomInt(&rndContext);
}
Uint32 SDLTest_RandomUint32()
Uint32 SDLTest_RandomUint32(void)
{
fuzzerInvocationCounter++;
return (Uint32)SDLTest_RandomInt(&rndContext);
}
Uint64 SDLTest_RandomUint64()
Uint64 SDLTest_RandomUint64(void)
{
union
{
@ -132,7 +132,7 @@ Uint64 SDLTest_RandomUint64()
return value.v64;
}
Sint64 SDLTest_RandomSint64()
Sint64 SDLTest_RandomSint64(void)
{
union
{
@ -153,21 +153,22 @@ Sint32 SDLTest_RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
{
Sint64 min = pMin;
Sint64 max = pMax;
Sint64 temp;
Sint64 number;
Uint64 range;
if (pMin > pMax) {
temp = min;
min = max;
max = temp;
min = pMax;
max = pMin;
} else if (pMin == pMax) {
return (Sint32)min;
}
number = SDLTest_RandomUint32();
/* invocation count increment in preceeding call */
return (Sint32)((number % ((max + 1) - min)) + min);
range = (Sint64)max - (Sint64)min;
if (range < SDL_MAX_SINT32) {
return (Sint32) (min + (Sint32) (SDLTest_RandomUint32() % (range + 1)));
} else {
const Uint64 add = SDLTest_RandomUint32() | SDLTest_RandomUint32();
return (Sint32) (min + (Sint64) (add % (range + 1)));
}
}
/* !
@ -425,24 +426,24 @@ Sint64 SDLTest_RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL
validDomain);
}
float SDLTest_RandomUnitFloat()
float SDLTest_RandomUnitFloat(void)
{
return SDLTest_RandomUint32() / (float)UINT_MAX;
}
float SDLTest_RandomFloat()
float SDLTest_RandomFloat(void)
{
return (float)(SDLTest_RandomUnitDouble() * 2.0 * (double)FLT_MAX - (double)(FLT_MAX));
}
double
SDLTest_RandomUnitDouble()
SDLTest_RandomUnitDouble(void)
{
return (double)(SDLTest_RandomUint64() >> 11) * (1.0 / 9007199254740992.0);
}
double
SDLTest_RandomDouble()
SDLTest_RandomDouble(void)
{
double r = 0.0;
double s = 1.0;
@ -456,7 +457,7 @@ SDLTest_RandomDouble()
return r;
}
char *SDLTest_RandomAsciiString()
char *SDLTest_RandomAsciiString(void)
{
return SDLTest_RandomAsciiStringWithMaximumLength(255);
}
@ -471,7 +472,9 @@ char *SDLTest_RandomAsciiStringWithMaximumLength(int maxLength)
}
size = (SDLTest_RandomUint32() % (maxLength + 1));
if (size == 0) {
size = 1;
}
return SDLTest_RandomAsciiStringOfSize(size);
}
@ -486,7 +489,7 @@ char *SDLTest_RandomAsciiStringOfSize(int size)
}
string = (char *)SDL_malloc((size + 1) * sizeof(char));
if (string == NULL) {
if (!string) {
return NULL;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -64,7 +64,7 @@ char *SDLTest_GenerateRunSeed(const int length)
/* Allocate output buffer */
seed = (char *)SDL_malloc((length + 1) * sizeof(char));
if (seed == NULL) {
if (!seed) {
SDLTest_LogError("SDL_malloc for run seed output buffer failed.");
SDL_Error(SDL_ENOMEM);
return NULL;
@ -108,17 +108,17 @@ static Uint64 SDLTest_GenerateExecKey(const char *runSeed, const char *suiteName
size_t entireStringLength;
char *buffer;
if (runSeed == NULL || runSeed[0] == '\0') {
if (!runSeed || runSeed[0] == '\0') {
SDLTest_LogError("Invalid runSeed string.");
return -1;
}
if (suiteName == NULL || suiteName[0] == '\0') {
if (!suiteName || suiteName[0] == '\0') {
SDLTest_LogError("Invalid suiteName string.");
return -1;
}
if (testName == NULL || testName[0] == '\0') {
if (!testName || testName[0] == '\0') {
SDLTest_LogError("Invalid testName string.");
return -1;
}
@ -139,7 +139,7 @@ static Uint64 SDLTest_GenerateExecKey(const char *runSeed, const char *suiteName
iterationStringLength = SDL_strlen(iterationString);
entireStringLength = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1;
buffer = (char *)SDL_malloc(entireStringLength);
if (buffer == NULL) {
if (!buffer) {
SDLTest_LogError("Failed to allocate buffer for execKey generation.");
SDL_Error(SDL_ENOMEM);
return 0;
@ -171,7 +171,7 @@ static SDL_TimerID SDLTest_SetTestTimeout(int timeout, void(SDLCALL *callback)(v
Uint32 timeoutInMilliseconds;
SDL_TimerID timerID;
if (callback == NULL) {
if (!callback) {
SDLTest_LogError("Timeout callback can't be NULL");
return -1;
}
@ -229,7 +229,7 @@ static int SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_
int testResult = 0;
int fuzzerCount;
if (testSuite == NULL || testCase == NULL || testSuite->name == NULL || testCase->name == NULL) {
if (!testSuite || !testCase || !testSuite->name || !testCase->name) {
SDLTest_LogError("Setup failure: testSuite or testCase references NULL");
return TEST_RESULT_SETUP_FAILURE;
}
@ -339,7 +339,7 @@ static void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites)
#endif
/* Gets a timer value in seconds */
static float GetClock()
static float GetClock(void)
{
float currentClock = SDL_GetPerformanceCounter() / (float)SDL_GetPerformanceFrequency();
return currentClock;
@ -402,9 +402,9 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
}
/* Generate run see if we don't have one already */
if (userRunSeed == NULL || userRunSeed[0] == '\0') {
if (!userRunSeed || userRunSeed[0] == '\0') {
char *tmp = SDLTest_GenerateRunSeed(16);
if (tmp == NULL) {
if (!tmp) {
SDLTest_LogError("Generating a random seed failed");
return 2;
}
@ -445,20 +445,20 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
/* Pre-allocate an array for tracking failed tests (potentially all test cases) */
failedTests = (const SDLTest_TestCaseReference **)SDL_malloc(totalNumberOfTests * sizeof(SDLTest_TestCaseReference *));
if (failedTests == NULL) {
if (!failedTests) {
SDLTest_LogError("Unable to allocate cache for failed tests");
SDL_Error(SDL_ENOMEM);
return -1;
}
/* Initialize filtering */
if (filter != NULL && filter[0] != '\0') {
if (filter && filter[0] != '\0') {
/* Loop over all suites to check if we have a filter match */
suiteCounter = 0;
while (testSuites[suiteCounter] && suiteFilter == 0) {
testSuite = testSuites[suiteCounter];
suiteCounter++;
if (testSuite->name != NULL && SDL_strcasecmp(filter, testSuite->name) == 0) {
if (testSuite->name && SDL_strcasecmp(filter, testSuite->name) == 0) {
/* Matched a suite name */
suiteFilter = 1;
suiteFilterName = testSuite->name;
@ -471,7 +471,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
while (testSuite->testCases[testCounter] && testFilter == 0) {
testCase = testSuite->testCases[testCounter];
testCounter++;
if (testCase->name != NULL && SDL_strcasecmp(filter, testCase->name) == 0) {
if (testCase->name && SDL_strcasecmp(filter, testCase->name) == 0) {
/* Matched a test name */
suiteFilter = 1;
suiteFilterName = testSuite->name;
@ -487,14 +487,14 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
SDLTest_LogError("Filter '%s' did not match any test suite/case.", filter);
for (suiteCounter = 0; testSuites[suiteCounter]; ++suiteCounter) {
testSuite = testSuites[suiteCounter];
if (testSuite->name != NULL) {
if (testSuite->name) {
SDLTest_Log("Test suite: %s", testSuite->name);
}
/* Within each suite, loop over all test cases to check if we have a filter match */
for (testCounter = 0; testSuite->testCases[testCounter]; ++testCounter) {
testCase = testSuite->testCases[testCounter];
SDLTest_Log(" test: %s", testCase->name);
SDLTest_Log(" test: %s%s", testCase->name, testCase->enabled ? "" : " (disabled)");
}
}
SDLTest_Log("Exit code: 2");
@ -511,7 +511,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
suiteCounter++;
/* Filter suite if flag set and we have a name */
if (suiteFilter == 1 && suiteFilterName != NULL && testSuite->name != NULL &&
if (suiteFilter == 1 && suiteFilterName && testSuite->name &&
SDL_strcasecmp(suiteFilterName, testSuite->name) != 0) {
/* Skip suite */
SDLTest_Log("===== Test Suite %i: '%s' skipped\n",
@ -540,7 +540,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
testCounter++;
/* Filter tests if flag set and we have a name */
if (testFilter == 1 && testFilterName != NULL && testCase->name != NULL &&
if (testFilter == 1 && testFilterName && testCase->name &&
SDL_strcasecmp(testFilterName, testCase->name) != 0) {
/* Skip test */
SDLTest_Log("===== Test Case %i.%i: '%s' skipped\n",
@ -562,7 +562,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
suiteCounter,
testCounter,
currentTestName);
if (testCase->description != NULL && testCase->description[0] != '\0') {
if (testCase->description && testCase->description[0] != '\0') {
SDLTest_Log("Test Description: '%s'",
(testCase->description) ? testCase->description : SDLTEST_INVALID_NAME_FORMAT);
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -540,26 +540,15 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlit = {
/**
* \brief Returns the Blit test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlit()
SDL_Surface *SDLTest_ImageBlit(void)
{
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom(
(void *)SDLTest_imageBlit.pixel_data,
SDLTest_imageBlit.width,
SDLTest_imageBlit.height,
SDLTest_imageBlit.bytes_per_pixel * 8,
SDLTest_imageBlit.width * SDLTest_imageBlit.bytes_per_pixel,
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0xff000000, /* Red bit mask. */
0x00ff0000, /* Green bit mask. */
0x0000ff00, /* Blue bit mask. */
0x000000ff /* Alpha bit mask. */
#else
0x000000ff, /* Red bit mask. */
0x0000ff00, /* Green bit mask. */
0x00ff0000, /* Blue bit mask. */
0xff000000 /* Alpha bit mask. */
#endif
);
SDL_PIXELFORMAT_RGB24);
return surface;
}
@ -1025,26 +1014,15 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitColor = {
/**
* \brief Returns the BlitColor test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitColor()
SDL_Surface *SDLTest_ImageBlitColor(void)
{
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom(
(void *)SDLTest_imageBlitColor.pixel_data,
SDLTest_imageBlitColor.width,
SDLTest_imageBlitColor.height,
SDLTest_imageBlitColor.bytes_per_pixel * 8,
SDLTest_imageBlitColor.width * SDLTest_imageBlitColor.bytes_per_pixel,
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0xff000000, /* Red bit mask. */
0x00ff0000, /* Green bit mask. */
0x0000ff00, /* Blue bit mask. */
0x000000ff /* Alpha bit mask. */
#else
0x000000ff, /* Red bit mask. */
0x0000ff00, /* Green bit mask. */
0x00ff0000, /* Blue bit mask. */
0xff000000 /* Alpha bit mask. */
#endif
);
SDL_PIXELFORMAT_RGB24);
return surface;
}
@ -1673,26 +1651,15 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitAlpha = {
/**
* \brief Returns the BlitAlpha test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitAlpha()
SDL_Surface *SDLTest_ImageBlitAlpha(void)
{
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom(
(void *)SDLTest_imageBlitAlpha.pixel_data,
SDLTest_imageBlitAlpha.width,
SDLTest_imageBlitAlpha.height,
SDLTest_imageBlitAlpha.bytes_per_pixel * 8,
SDLTest_imageBlitAlpha.width * SDLTest_imageBlitAlpha.bytes_per_pixel,
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0xff000000, /* Red bit mask. */
0x00ff0000, /* Green bit mask. */
0x0000ff00, /* Blue bit mask. */
0x000000ff /* Alpha bit mask. */
#else
0x000000ff, /* Red bit mask. */
0x0000ff00, /* Green bit mask. */
0x00ff0000, /* Blue bit mask. */
0xff000000 /* Alpha bit mask. */
#endif
);
SDL_PIXELFORMAT_RGB24);
return surface;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -580,26 +580,15 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAdd = {
/**
* \brief Returns the BlitBlendAdd test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitBlendAdd()
SDL_Surface *SDLTest_ImageBlitBlendAdd(void)
{
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom(
(void *)SDLTest_imageBlitBlendAdd.pixel_data,
SDLTest_imageBlitBlendAdd.width,
SDLTest_imageBlitBlendAdd.height,
SDLTest_imageBlitBlendAdd.bytes_per_pixel * 8,
SDLTest_imageBlitBlendAdd.width * SDLTest_imageBlitBlendAdd.bytes_per_pixel,
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0xff000000, /* Red bit mask. */
0x00ff0000, /* Green bit mask. */
0x0000ff00, /* Blue bit mask. */
0x000000ff /* Alpha bit mask. */
#else
0x000000ff, /* Red bit mask. */
0x0000ff00, /* Green bit mask. */
0x00ff0000, /* Blue bit mask. */
0xff000000 /* Alpha bit mask. */
#endif
);
SDL_PIXELFORMAT_RGB24);
return surface;
}
@ -1182,26 +1171,15 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlend = {
/**
* \brief Returns the BlitBlend test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitBlend()
SDL_Surface *SDLTest_ImageBlitBlend(void)
{
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom(
(void *)SDLTest_imageBlitBlend.pixel_data,
SDLTest_imageBlitBlend.width,
SDLTest_imageBlitBlend.height,
SDLTest_imageBlitBlend.bytes_per_pixel * 8,
SDLTest_imageBlitBlend.width * SDLTest_imageBlitBlend.bytes_per_pixel,
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0xff000000, /* Red bit mask. */
0x00ff0000, /* Green bit mask. */
0x0000ff00, /* Blue bit mask. */
0x000000ff /* Alpha bit mask. */
#else
0x000000ff, /* Red bit mask. */
0x0000ff00, /* Green bit mask. */
0x00ff0000, /* Blue bit mask. */
0xff000000 /* Alpha bit mask. */
#endif
);
SDL_PIXELFORMAT_RGB24);
return surface;
}
@ -1614,26 +1592,15 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendMod = {
/**
* \brief Returns the BlitBlendMod test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitBlendMod()
SDL_Surface *SDLTest_ImageBlitBlendMod(void)
{
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom(
(void *)SDLTest_imageBlitBlendMod.pixel_data,
SDLTest_imageBlitBlendMod.width,
SDLTest_imageBlitBlendMod.height,
SDLTest_imageBlitBlendMod.bytes_per_pixel * 8,
SDLTest_imageBlitBlendMod.width * SDLTest_imageBlitBlendMod.bytes_per_pixel,
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0xff000000, /* Red bit mask. */
0x00ff0000, /* Green bit mask. */
0x0000ff00, /* Blue bit mask. */
0x000000ff /* Alpha bit mask. */
#else
0x000000ff, /* Red bit mask. */
0x0000ff00, /* Green bit mask. */
0x00ff0000, /* Blue bit mask. */
0xff000000 /* Alpha bit mask. */
#endif
);
SDL_PIXELFORMAT_RGB24);
return surface;
}
@ -2429,26 +2396,15 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendNone = {
/**
* \brief Returns the BlitBlendNone test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitBlendNone()
SDL_Surface *SDLTest_ImageBlitBlendNone(void)
{
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom(
(void *)SDLTest_imageBlitBlendNone.pixel_data,
SDLTest_imageBlitBlendNone.width,
SDLTest_imageBlitBlendNone.height,
SDLTest_imageBlitBlendNone.bytes_per_pixel * 8,
SDLTest_imageBlitBlendNone.width * SDLTest_imageBlitBlendNone.bytes_per_pixel,
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0xff000000, /* Red bit mask. */
0x00ff0000, /* Green bit mask. */
0x0000ff00, /* Blue bit mask. */
0x000000ff /* Alpha bit mask. */
#else
0x000000ff, /* Red bit mask. */
0x0000ff00, /* Green bit mask. */
0x00ff0000, /* Blue bit mask. */
0xff000000 /* Alpha bit mask. */
#endif
);
SDL_PIXELFORMAT_RGB24);
return surface;
}
@ -2976,26 +2932,15 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAll = {
/**
* \brief Returns the BlitBlendAll test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitBlendAll()
SDL_Surface *SDLTest_ImageBlitBlendAll(void)
{
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom(
(void *)SDLTest_imageBlitBlendAll.pixel_data,
SDLTest_imageBlitBlendAll.width,
SDLTest_imageBlitBlendAll.height,
SDLTest_imageBlitBlendAll.bytes_per_pixel * 8,
SDLTest_imageBlitBlendAll.width * SDLTest_imageBlitBlendAll.bytes_per_pixel,
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0xff000000, /* Red bit mask. */
0x00ff0000, /* Green bit mask. */
0x0000ff00, /* Blue bit mask. */
0x000000ff /* Alpha bit mask. */
#else
0x000000ff, /* Red bit mask. */
0x0000ff00, /* Green bit mask. */
0x00ff0000, /* Blue bit mask. */
0xff000000 /* Alpha bit mask. */
#endif
);
SDL_PIXELFORMAT_RGB24);
return surface;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -223,26 +223,15 @@ static const SDLTest_SurfaceImage_t SDLTest_imageFace = {
/**
* \brief Returns the Face test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageFace()
SDL_Surface *SDLTest_ImageFace(void)
{
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom(
(void *)SDLTest_imageFace.pixel_data,
SDLTest_imageFace.width,
SDLTest_imageFace.height,
SDLTest_imageFace.bytes_per_pixel * 8,
SDLTest_imageFace.width * SDLTest_imageFace.bytes_per_pixel,
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0xff000000, /* Red bit mask. */
0x00ff0000, /* Green bit mask. */
0x0000ff00, /* Blue bit mask. */
0x000000ff /* Alpha bit mask. */
#else
0x000000ff, /* Red bit mask. */
0x0000ff00, /* Green bit mask. */
0x00ff0000, /* Blue bit mask. */
0xff000000 /* Alpha bit mask. */
#endif
);
SDL_PIXELFORMAT_RGBA32);
return surface;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -504,26 +504,15 @@ static const SDLTest_SurfaceImage_t SDLTest_imagePrimitives = {
/**
* \brief Returns the Primitives test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImagePrimitives()
SDL_Surface *SDLTest_ImagePrimitives(void)
{
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom(
(void *)SDLTest_imagePrimitives.pixel_data,
SDLTest_imagePrimitives.width,
SDLTest_imagePrimitives.height,
SDLTest_imagePrimitives.bytes_per_pixel * 8,
SDLTest_imagePrimitives.width * SDLTest_imagePrimitives.bytes_per_pixel,
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0xff000000, /* Red bit mask. */
0x00ff0000, /* Green bit mask. */
0x0000ff00, /* Blue bit mask. */
0x000000ff /* Alpha bit mask. */
#else
0x000000ff, /* Red bit mask. */
0x0000ff00, /* Green bit mask. */
0x00ff0000, /* Blue bit mask. */
0xff000000 /* Alpha bit mask. */
#endif
);
SDL_PIXELFORMAT_RGB24);
return surface;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -677,26 +677,15 @@ static const SDLTest_SurfaceImage_t SDLTest_imagePrimitivesBlend = {
/**
* \brief Returns the PrimitivesBlend test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImagePrimitivesBlend()
SDL_Surface *SDLTest_ImagePrimitivesBlend(void)
{
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom(
(void *)SDLTest_imagePrimitivesBlend.pixel_data,
SDLTest_imagePrimitivesBlend.width,
SDLTest_imagePrimitivesBlend.height,
SDLTest_imagePrimitivesBlend.bytes_per_pixel * 8,
SDLTest_imagePrimitivesBlend.width * SDLTest_imagePrimitivesBlend.bytes_per_pixel,
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0xff000000, /* Red bit mask. */
0x00ff0000, /* Green bit mask. */
0x0000ff00, /* Blue bit mask. */
0x000000ff /* Alpha bit mask. */
#else
0x000000ff, /* Red bit mask. */
0x0000ff00, /* Green bit mask. */
0x00ff0000, /* Blue bit mask. */
0xff000000 /* Alpha bit mask. */
#endif
);
SDL_PIXELFORMAT_RGB24);
return surface;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -113,7 +113,7 @@ static unsigned char MD5PADDING[64] = {
void SDLTest_Md5Init(SDLTest_Md5Context *mdContext)
{
if (mdContext == NULL) {
if (!mdContext) {
return;
}
@ -141,10 +141,10 @@ void SDLTest_Md5Update(SDLTest_Md5Context *mdContext, unsigned char *inBuf,
int mdi;
unsigned int i, ii;
if (mdContext == NULL) {
if (!mdContext) {
return;
}
if (inBuf == NULL || inLen < 1) {
if (!inBuf || inLen < 1) {
return;
}
@ -193,7 +193,7 @@ void SDLTest_Md5Final(SDLTest_Md5Context *mdContext)
unsigned int i, ii;
unsigned int padLen;
if (mdContext == NULL) {
if (!mdContext) {
return;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -20,6 +20,8 @@
*/
#include "SDL_config.h"
#include "SDL_assert.h"
#include "SDL_atomic.h"
#include "SDL_loadso.h"
#include "SDL_stdinc.h"
#include "SDL_log.h"
#include "SDL_test_crc32.h"
@ -28,6 +30,31 @@
#ifdef HAVE_LIBUNWIND_H
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#ifndef unw_get_proc_name_by_ip
#define SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
static SDL_bool s_unwind_symbol_names = SDL_TRUE;
#endif
#endif
#if defined(__WIN32__) && !defined(__WATCOMC__)
#define WIN32_WITH_DBGHELP
#endif
#ifdef WIN32_WITH_DBGHELP
#include <windows.h>
#include <dbghelp.h>
static struct {
HMODULE module;
BOOL (WINAPI *pSymInitialize)(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess);
BOOL (WINAPI *pSymFromAddr)(HANDLE hProcess, DWORD64 Address, PDWORD64 Displacement, PSYMBOL_INFO Symbol);
BOOL (WINAPI *pSymGetLineFromAddr64)(HANDLE hProcess, DWORD64 qwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line);
} dyn_dbghelp;
/* older SDKs might not have this: */
__declspec(dllimport) USHORT WINAPI RtlCaptureStackBackTrace(ULONG FramesToSkip, ULONG FramesToCapture, PVOID* BackTrace, PULONG BackTraceHash);
#define CaptureStackBackTrace RtlCaptureStackBackTrace
#endif
/* This is a simple tracking allocator to demonstrate the use of SDL's
@ -37,13 +64,17 @@
for production code.
*/
#define MAXIMUM_TRACKED_STACK_DEPTH 16
typedef struct SDL_tracked_allocation
{
void *mem;
size_t size;
Uint64 stack[10];
char stack_names[10][256];
Uint64 stack[MAXIMUM_TRACKED_STACK_DEPTH];
struct SDL_tracked_allocation *next;
#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
char stack_names[MAXIMUM_TRACKED_STACK_DEPTH][256];
#endif
} SDL_tracked_allocation;
static SDLTest_Crc32Context s_crc32_context;
@ -53,6 +84,16 @@ static SDL_realloc_func SDL_realloc_orig = NULL;
static SDL_free_func SDL_free_orig = NULL;
static int s_previous_allocations = 0;
static SDL_tracked_allocation *s_tracked_allocations[256];
static SDL_atomic_t s_lock;
#define LOCK_ALLOCATOR() \
do { \
if (SDL_AtomicCAS(&s_lock, 0, 1)) { \
break; \
} \
SDL_CPUPauseInstruction(); \
} while (SDL_TRUE)
#define UNLOCK_ALLOCATOR() do { SDL_AtomicSet(&s_lock, 0); } while (0)
static unsigned int get_allocation_bucket(void *mem)
{
@ -66,12 +107,17 @@ static unsigned int get_allocation_bucket(void *mem)
static SDL_bool SDL_IsAllocationTracked(void *mem)
{
SDL_tracked_allocation *entry;
int index = get_allocation_bucket(mem);
int index;
LOCK_ALLOCATOR();
index = get_allocation_bucket(mem);
for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
if (mem == entry->mem) {
UNLOCK_ALLOCATOR();
return SDL_TRUE;
}
}
UNLOCK_ALLOCATOR();
return SDL_FALSE;
}
@ -83,8 +129,10 @@ static void SDL_TrackAllocation(void *mem, size_t size)
if (SDL_IsAllocationTracked(mem)) {
return;
}
LOCK_ALLOCATOR();
entry = (SDL_tracked_allocation *)SDL_malloc_orig(sizeof(*entry));
if (entry == NULL) {
if (!entry) {
UNLOCK_ALLOCATOR();
return;
}
entry->mem = mem;
@ -103,15 +151,20 @@ static void SDL_TrackAllocation(void *mem, size_t size)
stack_index = 0;
while (unw_step(&cursor) > 0) {
unw_word_t offset, pc;
unw_word_t pc;
#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
unw_word_t offset;
char sym[236];
#endif
unw_get_reg(&cursor, UNW_REG_IP, &pc);
entry->stack[stack_index] = pc;
if (unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) {
#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
if (s_unwind_symbol_names && unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) {
SDL_snprintf(entry->stack_names[stack_index], sizeof(entry->stack_names[stack_index]), "%s+0x%llx", sym, (unsigned long long)offset);
}
#endif
++stack_index;
if (stack_index == SDL_arraysize(entry->stack)) {
@ -119,10 +172,24 @@ static void SDL_TrackAllocation(void *mem, size_t size)
}
}
}
#elif defined(WIN32_WITH_DBGHELP)
{
Uint32 count;
PVOID frames[63];
Uint32 i;
count = CaptureStackBackTrace(1, SDL_arraysize(frames), frames, NULL);
count = SDL_min(count, MAXIMUM_TRACKED_STACK_DEPTH);
for (i = 0; i < count; i++) {
entry->stack[i] = (Uint64)(uintptr_t)frames[i];
}
}
#endif /* HAVE_LIBUNWIND_H */
entry->next = s_tracked_allocations[index];
s_tracked_allocations[index] = entry;
UNLOCK_ALLOCATOR();
}
static void SDL_UntrackAllocation(void *mem)
@ -130,6 +197,7 @@ static void SDL_UntrackAllocation(void *mem)
SDL_tracked_allocation *entry, *prev;
int index = get_allocation_bucket(mem);
LOCK_ALLOCATOR();
prev = NULL;
for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
if (mem == entry->mem) {
@ -139,10 +207,12 @@ static void SDL_UntrackAllocation(void *mem)
s_tracked_allocations[index] = entry->next;
}
SDL_free_orig(entry);
UNLOCK_ALLOCATOR();
return;
}
prev = entry;
}
UNLOCK_ALLOCATOR();
}
static void *SDLCALL SDLTest_TrackedMalloc(size_t size)
@ -184,7 +254,7 @@ static void *SDLCALL SDLTest_TrackedRealloc(void *ptr, size_t size)
static void SDLCALL SDLTest_TrackedFree(void *ptr)
{
if (ptr == NULL) {
if (!ptr) {
return;
}
@ -195,7 +265,7 @@ static void SDLCALL SDLTest_TrackedFree(void *ptr)
SDL_free_orig(ptr);
}
int SDLTest_TrackAllocations()
int SDLTest_TrackAllocations(void)
{
if (SDL_malloc_orig) {
return 0;
@ -207,6 +277,41 @@ int SDLTest_TrackAllocations()
if (s_previous_allocations != 0) {
SDL_Log("SDLTest_TrackAllocations(): There are %d previous allocations, disabling free() validation", s_previous_allocations);
}
#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
do {
/* Don't use SDL_GetHint: SDL_malloc is off limits. */
const char *env_trackmem = SDL_getenv("SDL_TRACKMEM_SYMBOL_NAMES");
if (env_trackmem) {
if (SDL_strcasecmp(env_trackmem, "1") == 0 || SDL_strcasecmp(env_trackmem, "yes") == 0 || SDL_strcasecmp(env_trackmem, "true") == 0) {
s_unwind_symbol_names = SDL_TRUE;
} else if (SDL_strcasecmp(env_trackmem, "0") == 0 || SDL_strcasecmp(env_trackmem, "no") == 0 || SDL_strcasecmp(env_trackmem, "false") == 0) {
s_unwind_symbol_names = SDL_FALSE;
}
}
} while (0);
#elif defined(WIN32_WITH_DBGHELP)
do {
dyn_dbghelp.module = SDL_LoadObject("dbghelp.dll");
if (!dyn_dbghelp.module) {
goto dbghelp_failed;
}
dyn_dbghelp.pSymInitialize = (void *)SDL_LoadFunction(dyn_dbghelp.module, "SymInitialize");
dyn_dbghelp.pSymFromAddr = (void *)SDL_LoadFunction(dyn_dbghelp.module, "SymFromAddr");
dyn_dbghelp.pSymGetLineFromAddr64 = (void *)SDL_LoadFunction(dyn_dbghelp.module, "SymGetLineFromAddr64");
if (!dyn_dbghelp.pSymInitialize || !dyn_dbghelp.pSymFromAddr || !dyn_dbghelp.pSymGetLineFromAddr64) {
goto dbghelp_failed;
}
if (!dyn_dbghelp.pSymInitialize(GetCurrentProcess(), NULL, TRUE)) {
goto dbghelp_failed;
}
break;
dbghelp_failed:
if (dyn_dbghelp.module) {
SDL_UnloadObject(dyn_dbghelp.module);
dyn_dbghelp.module = NULL;
}
} while (0);
#endif
SDL_GetMemoryFunctions(&SDL_malloc_orig,
&SDL_calloc_orig,
@ -220,11 +325,11 @@ int SDLTest_TrackAllocations()
return 0;
}
void SDLTest_LogAllocations()
void SDLTest_LogAllocations(void)
{
char *message = NULL;
size_t message_size = 0;
char line[128], *tmp;
char line[256], *tmp;
SDL_tracked_allocation *entry;
int index, count, stack_index;
Uint64 total_allocated;
@ -261,10 +366,48 @@ void SDLTest_LogAllocations()
ADD_LINE();
/* Start at stack index 1 to skip our tracking functions */
for (stack_index = 1; stack_index < SDL_arraysize(entry->stack); ++stack_index) {
char stack_entry_description[256] = "???";
if (!entry->stack[stack_index]) {
break;
}
(void)SDL_snprintf(line, sizeof(line), "\t0x%" SDL_PRIx64 ": %s\n", entry->stack[stack_index], entry->stack_names[stack_index]);
#ifdef HAVE_LIBUNWIND_H
{
#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
if (s_unwind_symbol_names) {
(void)SDL_snprintf(stack_entry_description, sizeof(stack_entry_description), "%s", entry->stack_names[stack_index]);
}
#else
char name[256] = "???";
unw_word_t offset = 0;
unw_get_proc_name_by_ip(unw_local_addr_space, entry->stack[stack_index], name, sizeof(name), &offset, NULL);
(void)SDL_snprintf(stack_entry_description, sizeof(stack_entry_description), "%s+0x%llx", name, (long long unsigned int)offset);
#endif
}
#elif defined(WIN32_WITH_DBGHELP)
{
DWORD64 dwDisplacement = 0;
IMAGEHLP_LINE64 dbg_line;
char symbol_buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)symbol_buffer;
DWORD lineColumn = 0;
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
pSymbol->MaxNameLen = MAX_SYM_NAME;
dbg_line.SizeOfStruct = sizeof(dbg_line);
dbg_line.FileName = "";
dbg_line.LineNumber = 0;
if (dyn_dbghelp.module) {
if (!dyn_dbghelp.pSymFromAddr(GetCurrentProcess(), entry->stack[stack_index], &dwDisplacement, pSymbol)) {
SDL_strlcpy(pSymbol->Name, "???", MAX_SYM_NAME);
dwDisplacement = 0;
}
dyn_dbghelp.pSymGetLineFromAddr64(GetCurrentProcess(), (DWORD64)entry->stack[stack_index], &lineColumn, &dbg_line);
}
SDL_snprintf(stack_entry_description, sizeof(stack_entry_description), "%s+0x%I64x %s:%u", pSymbol->Name, dwDisplacement, dbg_line.FileName, (Uint32)dbg_line.LineNumber);
}
#endif
(void)SDL_snprintf(line, sizeof(line), "\t0x%" SDL_PRIx64 ": %s\n", entry->stack[stack_index], stack_entry_description);
ADD_LINE();
}
total_allocated += entry->size;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -40,7 +40,7 @@
void SDLTest_RandomInit(SDLTest_RandomContext *rndContext, unsigned int xi, unsigned int ci)
{
if (rndContext == NULL) {
if (!rndContext) {
return;
}
@ -68,7 +68,7 @@ void SDLTest_RandomInitTime(SDLTest_RandomContext *rndContext)
{
int a, b;
if (rndContext == NULL) {
if (!rndContext) {
return;
}
@ -85,7 +85,7 @@ unsigned int SDLTest_Random(SDLTest_RandomContext *rndContext)
{
unsigned int xh, xl;
if (rndContext == NULL) {
if (!rndContext) {
return -1;
}