Cleanup add brace (#6545)

* Add braces after if conditions

* More add braces after if conditions

* Add braces after while() conditions

* Fix compilation because of macro being modified

* Add braces to for loop

* Add braces after if/goto

* Move comments up

* Remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements after merge

* Fix inconsistent patterns are xxx == NULL vs !xxx

* More "{}" for "if() break;"  and "if() continue;"

* More "{}" after if() short statement

* More "{}" after "if () return;" statement

* More fix inconsistent patterns are xxx == NULL vs !xxx

* Revert some modificaion on SDL_RLEaccel.c

* SDL_RLEaccel: no short statement

* Cleanup 'if' where the bracket is in a new line

* Cleanup 'while' where the bracket is in a new line

* Cleanup 'for' where the bracket is in a new line

* Cleanup 'else' where the bracket is in a new line
This commit is contained in:
Sylvain Becker
2022-11-27 17:38:43 +01:00
committed by GitHub
parent 4958dafdc3
commit 6a2200823c
387 changed files with 6094 additions and 4633 deletions

View File

@@ -71,13 +71,10 @@ int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char
va_end(list);
/* Log pass or fail message */
if (assertCondition == ASSERT_FAIL)
{
if (assertCondition == ASSERT_FAIL) {
SDLTest_AssertsFailed++;
SDLTest_LogError(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Failed");
}
else
{
} else {
SDLTest_AssertsPassed++;
SDLTest_Log(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Passed");
}
@@ -120,12 +117,9 @@ void SDLTest_ResetAssertSummary()
void SDLTest_LogAssertSummary()
{
int totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed;
if (SDLTest_AssertsFailed == 0)
{
if (SDLTest_AssertsFailed == 0) {
SDLTest_Log(SDLTEST_ASSERT_SUMMARY_FORMAT, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
}
else
{
} else {
SDLTest_LogError(SDLTEST_ASSERT_SUMMARY_FORMAT, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
}
}

View File

@@ -69,7 +69,7 @@ SDLTest_CommonCreateState(char **argv, Uint32 flags)
}
state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state));
if (!state) {
if (state == NULL) {
SDL_OutOfMemory();
return NULL;
}
@@ -112,6 +112,16 @@ SDLTest_CommonCreateState(char **argv, Uint32 flags)
return state;
}
#define SEARCHARG(dim) \
while (*dim && *dim != ',') { \
++dim; \
} \
if (!*dim) { \
return -1; \
} \
*dim++ = '\0';
int
SDLTest_CommonArg(SDLTest_CommonState * state, int index)
{
@@ -305,20 +315,11 @@ SDLTest_CommonArg(SDLTest_CommonState * state, int index)
}
x = argv[index];
y = argv[index];
#define SEARCHARG(dim) \
while (*dim && *dim != ',') { \
++dim; \
} \
if (!*dim) { \
return -1; \
} \
*dim++ = '\0';
SEARCHARG(y)
w = y;
SEARCHARG(w)
h = w;
SEARCHARG(h)
#undef SEARCHARG
state->confine.x = SDL_atoi(x);
state->confine.y = SDL_atoi(y);
state->confine.w = SDL_atoi(w);
@@ -592,7 +593,7 @@ static const char *
BuildCommonUsageString(char **pstr, const char **strlist, const int numitems, const char **strlist2, const int numitems2)
{
char *str = *pstr;
if (!str) {
if (str == NULL) {
size_t len = SDL_strlen("[--trackmem]") + 2;
int i;
for (i = 0; i < numitems; i++) {
@@ -604,7 +605,7 @@ BuildCommonUsageString(char **pstr, const char **strlist, const int numitems, co
}
}
str = (char *) SDL_calloc(1, len);
if (!str) {
if (str == NULL) {
return ""; /* oh well. */
}
SDL_strlcat(str, "[--trackmem] ", len);
@@ -1005,7 +1006,7 @@ SDLTest_LoadIcon(const char *file)
icon = SDL_LoadBMP(file);
if (icon == NULL) {
SDL_Log("Couldn't load %s: %s\n", file, SDL_GetError());
return (NULL);
return NULL;
}
if (icon->format->palette) {
@@ -1013,7 +1014,7 @@ SDLTest_LoadIcon(const char *file)
SDL_SetColorKey(icon, 1, *((Uint8 *) icon->pixels));
}
return (icon);
return icon;
}
static SDL_HitTestResult SDLCALL
@@ -1165,8 +1166,9 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
SDL_Log(" Red Mask = 0x%.8" SDL_PRIx32 "\n", Rmask);
SDL_Log(" Green Mask = 0x%.8" SDL_PRIx32 "\n", Gmask);
SDL_Log(" Blue Mask = 0x%.8" SDL_PRIx32 "\n", Bmask);
if (Amask)
if (Amask) {
SDL_Log(" Alpha Mask = 0x%.8" SDL_PRIx32 "\n", Amask);
}
}
/* Print available fullscreen video modes */
@@ -1189,9 +1191,9 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
Gmask);
SDL_Log(" Blue Mask = 0x%.8" SDL_PRIx32 "\n",
Bmask);
if (Amask)
SDL_Log(" Alpha Mask = 0x%.8" SDL_PRIx32 "\n",
Amask);
if (Amask) {
SDL_Log(" Alpha Mask = 0x%.8" SDL_PRIx32 "\n", Amask);
}
}
}
}
@@ -1759,7 +1761,7 @@ SDLTest_ScreenShot(SDL_Renderer *renderer)
SDL_Rect viewport;
SDL_Surface *surface;
if (!renderer) {
if (renderer == NULL) {
return;
}
@@ -1771,7 +1773,7 @@ SDLTest_ScreenShot(SDL_Renderer *renderer)
0x000000FF, 0x0000FF00, 0x00FF0000,
#endif
0x00000000);
if (!surface) {
if (surface == NULL) {
SDL_Log("Couldn't create surface: %s\n", SDL_GetError());
return;
}
@@ -1796,7 +1798,7 @@ FullscreenTo(int index, int windowId)
Uint32 flags;
struct SDL_Rect rect = { 0, 0, 0, 0 };
SDL_Window *window = SDL_GetWindowFromID(windowId);
if (!window) {
if (window == NULL) {
return;
}
@@ -1936,10 +1938,18 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
int x, y;
SDL_GetWindowPosition(window, &x, &y);
if (event->key.keysym.sym == SDLK_UP) y -= delta;
if (event->key.keysym.sym == SDLK_DOWN) y += delta;
if (event->key.keysym.sym == SDLK_LEFT) x -= delta;
if (event->key.keysym.sym == SDLK_RIGHT) x += delta;
if (event->key.keysym.sym == SDLK_UP) {
y -= delta;
}
if (event->key.keysym.sym == SDLK_DOWN) {
y += delta;
}
if (event->key.keysym.sym == SDLK_LEFT) {
x -= delta;
}
if (event->key.keysym.sym == SDLK_RIGHT) {
x += delta;
}
SDL_Log("Setting position to (%d, %d)\n", x, y);
SDL_SetWindowPosition(window, x, y);

View File

@@ -3189,7 +3189,7 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c)
charWidth, charHeight, 32,
0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
if (character == NULL) {
return (-1);
return -1;
}
charpos = SDLTest_FontData + ci * charSize;
@@ -3222,7 +3222,7 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c)
* Check pointer
*/
if (cache->charTextureCache[ci] == NULL) {
return (-1);
return -1;
}
}
@@ -3239,7 +3239,7 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c)
*/
result |= SDL_RenderCopy(renderer, cache->charTextureCache[ci], &srect, &drect);
return (result);
return result;
}
/* Gets a unicode value from a UTF-8 encoded string
@@ -3350,14 +3350,14 @@ int SDLTest_DrawString(SDL_Renderer * renderer, int x, int y, const char *s)
len -= advance;
}
return (result);
return result;
}
SDLTest_TextWindow *SDLTest_TextWindowCreate(int x, int y, int w, int h)
{
SDLTest_TextWindow *textwin = (SDLTest_TextWindow *)SDL_malloc(sizeof(*textwin));
if ( !textwin ) {
if (textwin == NULL) {
return NULL;
}
@@ -3451,8 +3451,7 @@ void SDLTest_TextWindowClear(SDLTest_TextWindow *textwin)
{
int i;
for ( i = 0; i < textwin->numlines; ++i )
{
for ( i = 0; i < textwin->numlines; ++i ) {
if ( textwin->lines[i] ) {
SDL_free(textwin->lines[i]);
textwin->lines[i] = NULL;

View File

@@ -151,11 +151,11 @@ SDLTest_RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
Sint64 temp;
Sint64 number;
if(pMin > pMax) {
if (pMin > pMax) {
temp = min;
min = max;
max = temp;
} else if(pMin == pMax) {
} else if (pMin == pMax) {
return (Sint32)min;
}
@@ -477,7 +477,7 @@ SDLTest_RandomAsciiStringWithMaximumLength(int maxLength)
{
int size;
if(maxLength < 1) {
if (maxLength < 1) {
SDL_InvalidParamError("maxLength");
return NULL;
}
@@ -494,7 +494,7 @@ SDLTest_RandomAsciiStringOfSize(int size)
int counter;
if(size < 1) {
if (size < 1) {
SDL_InvalidParamError("size");
return NULL;
}
@@ -504,7 +504,7 @@ SDLTest_RandomAsciiStringOfSize(int size)
return NULL;
}
for(counter = 0; counter < size; ++counter) {
for (counter = 0; counter < size; ++counter) {
string[counter] = (char)SDLTest_RandomIntegerInRange(32, 126);
}

View File

@@ -228,14 +228,12 @@ SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_TestCaseRef
int testResult = 0;
int fuzzerCount;
if (testSuite==NULL || testCase==NULL || testSuite->name==NULL || testCase->name==NULL)
{
if (testSuite==NULL || testCase==NULL || testSuite->name==NULL || testCase->name==NULL) {
SDLTest_LogError("Setup failure: testSuite or testCase references NULL");
return TEST_RESULT_SETUP_FAILURE;
}
if (!testCase->enabled && forceTestRun == SDL_FALSE)
{
if (!testCase->enabled && forceTestRun == SDL_FALSE) {
SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Test", testCase->name, "Skipped (Disabled)");
return TEST_RESULT_SKIPPED;
}
@@ -320,7 +318,7 @@ static void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites)
/* Loop over all suites */
suiteCounter = 0;
while(&testSuites[suiteCounter]) {
while (&testSuites[suiteCounter]) {
testSuite=&testSuites[suiteCounter];
suiteCounter++;
SDLTest_Log("Test Suite %i - %s\n", suiteCounter,
@@ -328,8 +326,7 @@ static void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites)
/* Loop over all test cases */
testCounter = 0;
while(testSuite->testCases[testCounter])
{
while (testSuite->testCases[testCounter]) {
testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter];
testCounter++;
SDLTest_Log(" Test Case %i - %s: %s", testCounter,
@@ -430,8 +427,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
testSuite = testSuites[suiteCounter];
suiteCounter++;
testCounter = 0;
while (testSuite->testCases[testCounter])
{
while (testSuite->testCases[testCounter]) {
testCounter++;
totalNumberOfTests++;
}
@@ -504,7 +500,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
/* Loop over all suites */
suiteCounter = 0;
while(testSuites[suiteCounter]) {
while (testSuites[suiteCounter]) {
testSuite = testSuites[suiteCounter];
currentSuiteName = (testSuite->name ? testSuite->name : SDLTEST_INVALID_NAME_FORMAT);
suiteCounter++;
@@ -533,8 +529,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
/* Loop over all test cases */
testCounter = 0;
while(testSuite->testCases[testCounter])
{
while (testSuite->testCases[testCounter]) {
testCase = testSuite->testCases[testCounter];
currentTestName = (testCase->name ? testCase->name : SDLTEST_INVALID_NAME_FORMAT);
testCounter++;
@@ -569,8 +564,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
/* Loop over all iterations */
iterationCounter = 0;
while(iterationCounter < testIterations)
{
while (iterationCounter < testIterations) {
iterationCounter++;
if (userExecKey != 0) {
@@ -597,7 +591,9 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
/* Take time - test end */
testEndSeconds = GetClock();
runtime = testEndSeconds - testStartSeconds;
if (runtime < 0.0f) runtime = 0.0f;
if (runtime < 0.0f) {
runtime = 0.0f;
}
if (testIterations > 1) {
/* Log test runtime */
@@ -632,20 +628,19 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
/* Take time - suite end */
suiteEndSeconds = GetClock();
runtime = suiteEndSeconds - suiteStartSeconds;
if (runtime < 0.0f) runtime = 0.0f;
if (runtime < 0.0f) {
runtime = 0.0f;
}
/* Log suite runtime */
SDLTest_Log("Total Suite runtime: %.1f sec", runtime);
/* Log summary and final Suite result */
countSum = testPassedCount + testFailedCount + testSkippedCount;
if (testFailedCount == 0)
{
if (testFailedCount == 0) {
SDLTest_Log(SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Suite", currentSuiteName, "Passed");
}
else
{
} else {
SDLTest_LogError(SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Suite", currentSuiteName, "Failed");
}
@@ -656,21 +651,20 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
/* Take time - run end */
runEndSeconds = GetClock();
runtime = runEndSeconds - runStartSeconds;
if (runtime < 0.0f) runtime = 0.0f;
if (runtime < 0.0f) {
runtime = 0.0f;
}
/* Log total runtime */
SDLTest_Log("Total Run runtime: %.1f sec", runtime);
/* Log summary and final run result */
countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount;
if (totalTestFailedCount == 0)
{
if (totalTestFailedCount == 0) {
runResult = 0;
SDLTest_Log(SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Run /w seed", runSeed, "Passed");
}
else
{
} else {
runResult = 1;
SDLTest_LogError(SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Run /w seed", runSeed, "Failed");

View File

@@ -106,7 +106,9 @@ static unsigned char MD5PADDING[64] = {
void SDLTest_Md5Init(SDLTest_Md5Context * mdContext)
{
if (mdContext==NULL) return;
if (mdContext == NULL) {
return;
}
mdContext->i[0] = mdContext->i[1] = (MD5UINT4) 0;
@@ -132,8 +134,12 @@ void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf,
int mdi;
unsigned int i, ii;
if (mdContext == NULL) return;
if (inBuf == NULL || inLen < 1) return;
if (mdContext == NULL) {
return;
}
if (inBuf == NULL || inLen < 1) {
return;
}
/*
* compute number of bytes mod 64
@@ -143,8 +149,9 @@ void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf,
/*
* update number of bits
*/
if ((mdContext->i[0] + ((MD5UINT4) inLen << 3)) < mdContext->i[0])
if ((mdContext->i[0] + ((MD5UINT4)inLen << 3)) < mdContext->i[0]) {
mdContext->i[1]++;
}
mdContext->i[0] += ((MD5UINT4) inLen << 3);
mdContext->i[1] += ((MD5UINT4) inLen >> 29);
@@ -158,11 +165,9 @@ void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf,
* transform if necessary
*/
if (mdi == 0x40) {
for (i = 0, ii = 0; i < 16; i++, ii += 4)
in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) |
(((MD5UINT4) mdContext->in[ii + 2]) << 16) |
(((MD5UINT4) mdContext->in[ii + 1]) << 8) |
((MD5UINT4) mdContext->in[ii]);
for (i = 0, ii = 0; i < 16; i++, ii += 4) {
in[i] = (((MD5UINT4)mdContext->in[ii + 3]) << 24) | (((MD5UINT4)mdContext->in[ii + 2]) << 16) | (((MD5UINT4)mdContext->in[ii + 1]) << 8) | ((MD5UINT4)mdContext->in[ii]);
}
SDLTest_Md5Transform(mdContext->buf, in);
mdi = 0;
}
@@ -181,7 +186,9 @@ void SDLTest_Md5Final(SDLTest_Md5Context * mdContext)
unsigned int i, ii;
unsigned int padLen;
if (mdContext == NULL) return;
if (mdContext == NULL) {
return;
}
/*
* save number of bits
@@ -203,11 +210,9 @@ void SDLTest_Md5Final(SDLTest_Md5Context * mdContext)
/*
* append length in bits and transform
*/
for (i = 0, ii = 0; i < 14; i++, ii += 4)
in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) |
(((MD5UINT4) mdContext->in[ii + 2]) << 16) |
(((MD5UINT4) mdContext->in[ii + 1]) << 8) |
((MD5UINT4) mdContext->in[ii]);
for (i = 0, ii = 0; i < 14; i++, ii += 4) {
in[i] = (((MD5UINT4)mdContext->in[ii + 3]) << 24) | (((MD5UINT4)mdContext->in[ii + 2]) << 16) | (((MD5UINT4)mdContext->in[ii + 1]) << 8) | ((MD5UINT4)mdContext->in[ii]);
}
SDLTest_Md5Transform(mdContext->buf, in);
/*

View File

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

View File

@@ -36,7 +36,9 @@
void SDLTest_RandomInit(SDLTest_RandomContext * rndContext, unsigned int xi, unsigned int ci)
{
if (rndContext==NULL) return;
if (rndContext == NULL) {
return;
}
/*
* Choose a value for 'a' from this list
@@ -62,7 +64,9 @@ void SDLTest_RandomInitTime(SDLTest_RandomContext * rndContext)
{
int a, b;
if (rndContext==NULL) return;
if (rndContext == NULL) {
return;
}
srand((unsigned int)time(NULL));
a=rand();
@@ -77,7 +81,9 @@ unsigned int SDLTest_Random(SDLTest_RandomContext * rndContext)
{
unsigned int xh, xl;
if (rndContext==NULL) return -1;
if (rndContext == NULL) {
return -1;
}
xh = rndContext->x >> 16;
xl = rndContext->x & 65535;
@@ -85,9 +91,10 @@ unsigned int SDLTest_Random(SDLTest_RandomContext * rndContext)
rndContext->c =
xh * rndContext->ah + ((xh * rndContext->al) >> 16) +
((xl * rndContext->ah) >> 16);
if (xl * rndContext->al >= (~rndContext->c + 1))
if (xl * rndContext->al >= (~rndContext->c + 1)) {
rndContext->c++;
return (rndContext->x);
}
return rndContext->x;
}
/* vi: set ts=4 sw=4 expandtab: */