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

@@ -47,7 +47,7 @@ Uint16 SDL_crc16(Uint16 crc, const void *data, size_t len)
{
/* As an optimization we can precalculate a 256 entry table for each byte */
size_t i;
for(i = 0; i < len; ++i) {
for (i = 0; i < len; ++i) {
crc = crc16_for_byte((Uint8)crc ^ ((const Uint8*)data)[i]) ^ crc >> 8;
}
return crc;

View File

@@ -45,7 +45,7 @@ Uint32 SDL_crc32(Uint32 crc, const void *data, size_t len)
{
/* As an optimization we can precalculate a 256 entry table for each byte */
size_t i;
for(i = 0; i < len; ++i) {
for (i = 0; i < len; ++i) {
crc = crc32_for_byte((Uint8)crc ^ ((const Uint8*)data)[i]) ^ crc >> 8;
}
return crc;

View File

@@ -47,8 +47,8 @@ int
SDL_setenv(const char *name, const char *value, int overwrite)
{
/* Input validation */
if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) {
return (-1);
if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) {
return -1;
}
return setenv(name, value, overwrite);
@@ -58,8 +58,8 @@ int
SDL_setenv(const char *name, const char *value, int overwrite)
{
/* Input validation */
if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) {
return (-1);
if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) {
return -1;
}
if (!overwrite) {
@@ -81,8 +81,8 @@ SDL_setenv(const char *name, const char *value, int overwrite)
char *new_variable;
/* Input validation */
if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) {
return (-1);
if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) {
return -1;
}
if (getenv(name) != NULL) {
@@ -96,8 +96,8 @@ SDL_setenv(const char *name, const char *value, int overwrite)
/* This leaks. Sorry. Get a better OS so we don't have to do this. */
len = SDL_strlen(name) + SDL_strlen(value) + 2;
new_variable = (char *) SDL_malloc(len);
if (!new_variable) {
return (-1);
if (new_variable == NULL) {
return -1;
}
SDL_snprintf(new_variable, len, "%s=%s", name, value);
@@ -114,8 +114,8 @@ SDL_setenv(const char *name, const char *value, int overwrite)
char *new_variable;
/* Input validation */
if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) {
return (-1);
if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) {
return -1;
}
/* See if it already exists */
@@ -126,8 +126,8 @@ SDL_setenv(const char *name, const char *value, int overwrite)
/* Allocate memory for the variable */
len = SDL_strlen(name) + SDL_strlen(value) + 2;
new_variable = (char *) SDL_malloc(len);
if (!new_variable) {
return (-1);
if (new_variable == NULL) {
return -1;
}
SDL_snprintf(new_variable, len, "%s=%s", name, value);
@@ -165,7 +165,7 @@ SDL_setenv(const char *name, const char *value, int overwrite)
SDL_free(new_variable);
}
}
return (added ? 0 : -1);
return added ? 0 : -1;
}
#endif
@@ -180,7 +180,7 @@ SDL_getenv(const char *name)
#endif
/* Input validation */
if (!name || *name == '\0') {
if (name == NULL || *name == '\0') {
return NULL;
}
@@ -193,7 +193,7 @@ SDL_getenv(const char *name)
size_t bufferlen;
/* Input validation */
if (!name || *name == '\0') {
if (name == NULL || *name == '\0') {
return NULL;
}
@@ -221,14 +221,14 @@ SDL_getenv(const char *name)
char *value;
/* Input validation */
if (!name || *name == '\0') {
if (name == NULL || *name == '\0') {
return NULL;
}
value = (char *) 0;
if (SDL_env) {
len = SDL_strlen(name);
for (i = 0; SDL_env[i] && !value; ++i) {
for (i = 0; SDL_env[i] && value == NULL; ++i) {
if ((SDL_strncmp(SDL_env[i], name, len) == 0) &&
(SDL_env[i][len] == '=')) {
value = &SDL_env[i][len + 1];
@@ -307,7 +307,7 @@ main(int argc, char *argv[])
} else {
printf("failed\n");
}
return (0);
return 0;
}
#endif /* TEST_MAIN */

View File

@@ -168,16 +168,16 @@ getlocale(char *buffer, size_t bufsize)
char *ptr;
lang = SDL_getenv("LC_ALL");
if (!lang) {
if (lang == NULL) {
lang = SDL_getenv("LC_CTYPE");
}
if (!lang) {
if (lang == NULL) {
lang = SDL_getenv("LC_MESSAGES");
}
if (!lang) {
if (lang == NULL) {
lang = SDL_getenv("LANG");
}
if (!lang || !*lang || SDL_strcmp(lang, "C") == 0) {
if (lang == NULL || !*lang || SDL_strcmp(lang, "C") == 0) {
lang = "ASCII";
}
@@ -205,10 +205,10 @@ SDL_iconv_open(const char *tocode, const char *fromcode)
char fromcode_buffer[64];
char tocode_buffer[64];
if (!fromcode || !*fromcode) {
if (fromcode == NULL || !*fromcode) {
fromcode = getlocale(fromcode_buffer, sizeof(fromcode_buffer));
}
if (!tocode || !*tocode) {
if (tocode == NULL || !*tocode) {
tocode = getlocale(tocode_buffer, sizeof(tocode_buffer));
}
for (i = 0; i < SDL_arraysize(encodings); ++i) {
@@ -248,11 +248,11 @@ SDL_iconv(SDL_iconv_t cd,
Uint32 ch = 0;
size_t total;
if (!inbuf || !*inbuf) {
if (inbuf == NULL || !*inbuf) {
/* Reset the context */
return 0;
}
if (!outbuf || !*outbuf || !outbytesleft || !*outbytesleft) {
if (outbuf == NULL || !*outbuf || outbytesleft == NULL || !*outbytesleft) {
return SDL_ICONV_E2BIG;
}
src = *inbuf;
@@ -818,10 +818,10 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
cd = SDL_iconv_open(tocode, fromcode);
if (cd == (SDL_iconv_t) - 1) {
/* See if we can recover here (fixes iconv on Solaris 11) */
if (!tocode || !*tocode) {
if (tocode == NULL || !*tocode) {
tocode = "UTF-8";
}
if (!fromcode || !*fromcode) {
if (fromcode == NULL || !*fromcode) {
fromcode = "UTF-8";
}
cd = SDL_iconv_open(tocode, fromcode);
@@ -832,7 +832,7 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
stringsize = inbytesleft > 4 ? inbytesleft : 4;
string = (char *) SDL_malloc(stringsize);
if (!string) {
if (string == NULL) {
SDL_iconv_close(cd);
return NULL;
}
@@ -849,7 +849,7 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
char *oldstring = string;
stringsize *= 2;
string = (char *) SDL_realloc(string, stringsize);
if (!string) {
if (string == NULL) {
SDL_free(oldstring);
SDL_iconv_close(cd);
return NULL;

View File

@@ -93,7 +93,7 @@ SDL_ScanLong(const char *text, int count, int radix, long *valuep)
*valuep = value;
}
}
return (text - textstart);
return text - textstart;
}
#endif
@@ -133,7 +133,7 @@ SDL_ScanUnsignedLong(const char *text, int count, int radix, unsigned long *valu
if (valuep && text > textstart) {
*valuep = value;
}
return (text - textstart);
return text - textstart;
}
#endif
@@ -165,7 +165,7 @@ SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
if (valuep && text > textstart) {
*valuep = value;
}
return (text - textstart);
return text - textstart;
}
#endif
@@ -210,7 +210,7 @@ SDL_ScanLongLong(const char *text, int count, int radix, Sint64 * valuep)
*valuep = value;
}
}
return (text - textstart);
return text - textstart;
}
#endif
@@ -250,7 +250,7 @@ SDL_ScanUnsignedLongLong(const char *text, int count, int radix, Uint64 * valuep
if (valuep && text > textstart) {
*valuep = value;
}
return (text - textstart);
return text - textstart;
}
#endif
@@ -286,7 +286,7 @@ SDL_ScanFloat(const char *text, double *valuep)
*valuep = value;
}
}
return (text - textstart);
return text - textstart;
}
#endif
@@ -335,7 +335,7 @@ SDL_memcmp(const void *s1, const void *s2, size_t len)
char *s2p = (char *) s2;
while (len--) {
if (*s1p != *s2p) {
return (*s1p - *s2p);
return *s1p - *s2p;
}
++s1p;
++s2p;
@@ -418,7 +418,7 @@ wchar_t *
SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle)
{
#if defined(HAVE_WCSSTR)
return SDL_const_cast(wchar_t*,wcsstr(haystack, needle));
return SDL_const_cast(wchar_t *, wcsstr(haystack, needle));
#else
size_t length = SDL_wcslen(needle);
while (*haystack) {
@@ -438,8 +438,9 @@ SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
return wcscmp(str1, str2);
#else
while (*str1 && *str2) {
if (*str1 != *str2)
if (*str1 != *str2) {
break;
}
++str1;
++str2;
}
@@ -454,8 +455,9 @@ SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
return wcsncmp(str1, str2, maxlen);
#else
while (*str1 && *str2 && maxlen) {
if (*str1 != *str2)
if (*str1 != *str2) {
break;
}
++str1;
++str2;
--maxlen;
@@ -463,7 +465,7 @@ SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
if (!maxlen) {
return 0;
}
return (int) (*str1 - *str2);
return (int)(*str1 - *str2);
#endif /* HAVE_WCSNCMP */
}
@@ -487,8 +489,9 @@ SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2)
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
}
if (a != b)
if (a != b) {
break;
}
++str1;
++str2;
}
@@ -501,7 +504,7 @@ SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2)
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
}
return (int) ((unsigned int) a - (unsigned int) b);
return (int)((unsigned int)a - (unsigned int)b);
#endif /* HAVE__WCSICMP */
}
@@ -524,8 +527,9 @@ SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
}
if (a != b)
if (a != b) {
break;
}
++str1;
++str2;
--maxlen;
@@ -542,7 +546,7 @@ SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
}
return (int) ((unsigned int) a - (unsigned int) b);
return (int)((unsigned int)a - (unsigned int)b);
}
#endif /* HAVE__WCSNICMP */
}
@@ -580,8 +584,9 @@ SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_
c = (unsigned char)src[i];
trailing_bytes = UTF8_TrailingBytes(c);
if (trailing_bytes) {
if (bytes - i != trailing_bytes + 1)
if (bytes - i != trailing_bytes + 1) {
bytes = i;
}
break;
}
@@ -707,18 +712,18 @@ char *
SDL_strchr(const char *string, int c)
{
#ifdef HAVE_STRCHR
return SDL_const_cast(char*,strchr(string, c));
return SDL_const_cast(char *, strchr(string, c));
#elif defined(HAVE_INDEX)
return SDL_const_cast(char*,index(string, c));
return SDL_const_cast(char *, index(string, c));
#else
while (*string) {
if (*string == c) {
return (char *) string;
return (char *)string;
}
++string;
}
if (c == '\0') {
return (char *) string;
return (char *)string;
}
return NULL;
#endif /* HAVE_STRCHR */
@@ -728,14 +733,14 @@ char *
SDL_strrchr(const char *string, int c)
{
#ifdef HAVE_STRRCHR
return SDL_const_cast(char*,strrchr(string, c));
return SDL_const_cast(char *, strrchr(string, c));
#elif defined(HAVE_RINDEX)
return SDL_const_cast(char*,rindex(string, c));
return SDL_const_cast(char *, rindex(string, c));
#else
const char *bufp = string + SDL_strlen(string);
while (bufp >= string) {
if (*bufp == c) {
return (char *) bufp;
return (char *)bufp;
}
--bufp;
}
@@ -747,12 +752,12 @@ char *
SDL_strstr(const char *haystack, const char *needle)
{
#if defined(HAVE_STRSTR)
return SDL_const_cast(char*,strstr(haystack, needle));
return SDL_const_cast(char *, strstr(haystack, needle));
#else
size_t length = SDL_strlen(needle);
while (*haystack) {
if (SDL_strncmp(haystack, needle, length) == 0) {
return (char *) haystack;
return (char *)haystack;
}
++haystack;
}
@@ -764,12 +769,12 @@ char *
SDL_strcasestr(const char *haystack, const char *needle)
{
#if defined(HAVE_STRCASESTR)
return SDL_const_cast(char*,strcasestr(haystack, needle));
return SDL_const_cast(char *, strcasestr(haystack, needle));
#else
size_t length = SDL_strlen(needle);
while (*haystack) {
if (SDL_strncasecmp(haystack, needle, length) == 0) {
return (char *) haystack;
return (char *)haystack;
}
++haystack;
}
@@ -1038,10 +1043,11 @@ SDL_strcmp(const char *str1, const char *str2)
#else
int result;
while(1) {
while (1) {
result = (int)((unsigned char) *str1 - (unsigned char) *str2);
if (result != 0 || (*str1 == '\0'/* && *str2 == '\0'*/))
if (result != 0 || (*str1 == '\0'/* && *str2 == '\0'*/)) {
break;
}
++str1;
++str2;
}
@@ -1059,8 +1065,9 @@ SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
while (maxlen) {
result = (int) (unsigned char) *str1 - (unsigned char) *str2;
if (result != 0 || *str1 == '\0'/* && *str2 == '\0'*/)
if (result != 0 || *str1 == '\0'/* && *str2 == '\0'*/) {
break;
}
++str1;
++str2;
--maxlen;
@@ -1086,8 +1093,9 @@ SDL_strcasecmp(const char *str1, const char *str2)
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
result = a - b;
if (result != 0 || a == 0 /*&& b == 0*/)
if (result != 0 || a == 0 /*&& b == 0*/) {
break;
}
++str1;
++str2;
}
@@ -1109,14 +1117,16 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
a = SDL_tolower((unsigned char) *str1);
b = SDL_tolower((unsigned char) *str2);
result = a - b;
if (result != 0 || a == 0 /*&& b == 0*/)
if (result != 0 || a == 0 /*&& b == 0*/) {
break;
}
++str1;
++str2;
--maxlen;
}
if (maxlen == 0)
if (maxlen == 0) {
result = 0;
}
return result;
#endif /* HAVE_STRNCASECMP */
}
@@ -1144,7 +1154,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
{
int retval = 0;
if (!text || !*text) {
if (text == NULL || !*text) {
return -1;
}
@@ -1455,10 +1465,16 @@ SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
{
int retval;
if (!fmt) fmt = "";
if (!fmt) {
fmt = "";
}
retval = _vsnprintf(text, maxlen, fmt, ap);
if (maxlen > 0) text[maxlen-1] = '\0';
if (retval < 0) retval = (int) maxlen;
if (maxlen > 0) {
text[maxlen - 1] = '\0';
}
if (retval < 0) {
retval = (int)maxlen;
}
return retval;
}
#elif defined(HAVE_VSNPRINTF)
@@ -1508,8 +1524,9 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str
size_t width = info->width - sz;
size_t filllen;
if (info->precision >= 0 && (size_t)info->precision < sz)
if (info->precision >= 0 && (size_t)info->precision < sz) {
width += sz - (size_t)info->precision;
}
filllen = SDL_min(width, maxlen);
SDL_memset(text, fill, filllen);
@@ -1545,8 +1562,9 @@ SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info)
{/* left-pad num with zeroes. */
size_t sz, pad, have_sign;
if (!info)
if (info == NULL) {
return;
}
have_sign = 0;
if (*num == '-' || *num == '+') {
@@ -1732,8 +1750,7 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
if (*fmt >= '0' && *fmt <= '9') {
info.width = SDL_strtol(fmt, (char **)&fmt, 0);
}
else if (*fmt == '*') {
} else if (*fmt == '*') {
++fmt;
info.width = va_arg(ap, int);
}
@@ -1933,8 +1950,9 @@ SDL_vasprintf(char **strp, const char *fmt, va_list ap)
*strp = NULL;
p = (char *)SDL_malloc(size);
if (p == NULL)
if (p == NULL) {
return -1;
}
while (1) {
/* Try to print in the allocated space */
@@ -1943,8 +1961,9 @@ SDL_vasprintf(char **strp, const char *fmt, va_list ap)
va_end(aq);
/* Check error code */
if (retval < 0)
if (retval < 0) {
return retval;
}
/* If that worked, return the string */
if (retval < size) {