[SDL2] pointer boolean (#8523)

This commit is contained in:
Sylvain Becker
2023-11-10 15:30:56 +01:00
committed by GitHub
parent 4a3a9f3ad8
commit a14b948b6c
394 changed files with 2564 additions and 2559 deletions

View File

@@ -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;
}
@@ -592,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++) {
@@ -604,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);
@@ -992,7 +992,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;
}
@@ -1757,7 +1757,7 @@ static void SDLTest_ScreenShot(SDL_Renderer *renderer)
SDL_Rect viewport;
SDL_Surface *surface;
if (renderer == NULL) {
if (!renderer) {
return;
}
@@ -1769,7 +1769,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;
}
@@ -1793,7 +1793,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;
}

View File

@@ -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

@@ -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

@@ -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

@@ -488,7 +488,7 @@ char *SDLTest_RandomAsciiStringOfSize(int size)
}
string = (char *)SDL_malloc((size + 1) * sizeof(char));
if (string == NULL) {
if (!string) {
return NULL;
}

View File

@@ -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;
}
@@ -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,7 +487,7 @@ 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);
}
@@ -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

@@ -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

@@ -84,7 +84,7 @@ static void SDL_TrackAllocation(void *mem, size_t size)
return;
}
entry = (SDL_tracked_allocation *)SDL_malloc_orig(sizeof(*entry));
if (entry == NULL) {
if (!entry) {
return;
}
entry->mem = mem;
@@ -171,7 +171,7 @@ static void *SDLCALL SDLTest_TrackedRealloc(void *ptr, size_t size)
{
void *mem;
SDL_assert(ptr == NULL || SDL_IsAllocationTracked(ptr));
SDL_assert(!ptr || SDL_IsAllocationTracked(ptr));
mem = SDL_realloc_orig(ptr, size);
if (mem && mem != ptr) {
if (ptr) {
@@ -184,7 +184,7 @@ static void *SDLCALL SDLTest_TrackedRealloc(void *ptr, size_t size)
static void SDLCALL SDLTest_TrackedFree(void *ptr)
{
if (ptr == NULL) {
if (!ptr) {
return;
}

View File

@@ -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;
}