Pointer as bool (libsdl-org#7214)

This commit is contained in:
Sylvain
2023-11-09 22:29:15 +01:00
committed by Sam Lantinga
parent 23db971681
commit d8600f717e
371 changed files with 2448 additions and 2442 deletions

View File

@@ -40,7 +40,7 @@ char *SDL_GetPrefPath(const char *org, const char *app)
if (path) {
size_t pathlen = SDL_strlen(path) + 2;
char *fullpath = (char *)SDL_malloc(pathlen);
if (fullpath == NULL) {
if (!fullpath) {
SDL_OutOfMemory();
return NULL;
}

View File

@@ -42,17 +42,17 @@ char *SDL_GetPrefPath(const char *org, const char *app)
char *ptr = NULL;
size_t len = 0;
if (app == NULL) {
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (org == NULL) {
if (!org) {
org = "";
}
len = SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
retval = (char *)SDL_malloc(len);
if (retval == NULL) {
if (!retval) {
SDL_OutOfMemory();
return NULL;
}

View File

@@ -44,7 +44,7 @@ SDL_GetBasePath(void)
while (SDL_TRUE) {
void *ptr = SDL_realloc(path, buflen * sizeof(CHAR));
if (ptr == NULL) {
if (!ptr) {
SDL_free(path);
SDL_OutOfMemory();
return NULL;
@@ -90,13 +90,13 @@ SDL_GetPrefPath(const char *org, const char *app)
HRESULT result;
const char *csid = SDL_GetHint("SDL_GDK_SERVICE_CONFIGURATION_ID");
if (app == NULL) {
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
/* This should be set before calling SDL_GetPrefPath! */
if (csid == NULL) {
if (!csid) {
SDL_LogWarn(SDL_LOG_CATEGORY_SYSTEM, "Set SDL_GDK_SERVICE_CONFIGURATION_ID before calling SDL_GetPrefPath!");
return SDL_strdup("T:\\");
}

View File

@@ -47,11 +47,11 @@ char *SDL_GetBasePath(void)
rc = path.GetParent(&path); /* chop filename, keep directory. */
SDL_assert(rc == B_OK);
const char *str = path.Path();
SDL_assert(str != NULL);
SDL_assert(str);
const size_t len = SDL_strlen(str);
char *retval = (char *) SDL_malloc(len + 2);
if (retval == NULL) {
if (!retval) {
SDL_OutOfMemory();
return NULL;
}
@@ -70,11 +70,11 @@ char *SDL_GetPrefPath(const char *org, const char *app)
const char *append = "/config/settings/";
size_t len = SDL_strlen(home);
if (app == NULL) {
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (org == NULL) {
if (!org) {
org = "";
}
@@ -83,7 +83,7 @@ char *SDL_GetPrefPath(const char *org, const char *app)
}
len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
char *retval = (char *) SDL_malloc(len);
if (retval == NULL) {
if (!retval) {
SDL_OutOfMemory();
} else {
if (*org) {

View File

@@ -41,13 +41,13 @@ char *SDL_GetBasePath(void)
char *SDL_GetPrefPath(const char *org, const char *app)
{
char *pref_path = NULL;
if (app == NULL) {
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
pref_path = MakePrefPath(app);
if (pref_path == NULL) {
if (!pref_path) {
return NULL;
}

View File

@@ -79,11 +79,11 @@ char *SDL_GetPrefPath(const char *org, const char *app)
char *retval = NULL;
size_t len;
char *base = SDL_GetBasePath();
if (app == NULL) {
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (org == NULL) {
if (!org) {
org = "";
}

View File

@@ -47,11 +47,11 @@ char *SDL_GetPrefPath(const char *org, const char *app)
char *retval = NULL;
size_t len;
char *base = SDL_GetBasePath();
if (app == NULL) {
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (org == NULL) {
if (!org) {
org = "";
}

View File

@@ -34,21 +34,21 @@ static char *SDL_unixify_std(const char *ro_path, char *buffer, size_t buf_len,
{
const char *const in_buf = buffer; /* = NULL if we allocate the buffer. */
if (buffer == NULL) {
if (!buffer) {
/* This matches the logic in __unixify, with an additional byte for the
* extra path separator.
*/
buf_len = SDL_strlen(ro_path) + 14 + 1;
buffer = SDL_malloc(buf_len);
if (buffer == NULL) {
if (!buffer) {
SDL_OutOfMemory();
return NULL;
}
}
if (!__unixify_std(ro_path, buffer, buf_len, filetype)) {
if (in_buf == NULL) {
if (!in_buf) {
SDL_free(buffer);
}
@@ -88,7 +88,7 @@ static char *canonicalisePath(const char *path, const char *pathVar)
regs.r[5] = 1 - regs.r[5];
buf = SDL_malloc(regs.r[5]);
if (buf == NULL) {
if (!buf) {
SDL_OutOfMemory();
return NULL;
}
@@ -117,7 +117,7 @@ static _kernel_oserror *createDirectoryRecursive(char *path)
*ptr = '\0';
error = _kernel_swi(OS_File, &regs, &regs);
*ptr = '.';
if (error != NULL) {
if (error) {
return error;
}
}
@@ -137,13 +137,13 @@ char *SDL_GetBasePath(void)
}
canon = canonicalisePath((const char *)regs.r[0], "Run$Path");
if (canon == NULL) {
if (!canon) {
return NULL;
}
/* chop off filename. */
ptr = SDL_strrchr(canon, '.');
if (ptr != NULL) {
if (ptr) {
*ptr = '\0';
}
@@ -158,22 +158,22 @@ char *SDL_GetPrefPath(const char *org, const char *app)
size_t len;
_kernel_oserror *error;
if (app == NULL) {
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (org == NULL) {
if (!org) {
org = "";
}
canon = canonicalisePath("<Choices$Write>", "Run$Path");
if (canon == NULL) {
if (!canon) {
return NULL;
}
len = SDL_strlen(canon) + SDL_strlen(org) + SDL_strlen(app) + 4;
dir = (char *)SDL_malloc(len);
if (dir == NULL) {
if (!dir) {
SDL_OutOfMemory();
SDL_free(canon);
return NULL;
@@ -188,7 +188,7 @@ char *SDL_GetPrefPath(const char *org, const char *app)
SDL_free(canon);
error = createDirectoryRecursive(dir);
if (error != NULL) {
if (error) {
SDL_SetError("Couldn't create directory: %s", error->errmess);
SDL_free(dir);
return NULL;

View File

@@ -47,7 +47,7 @@ static char *readSymLink(const char *path)
while (1) {
char *ptr = (char *)SDL_realloc(retval, (size_t)len);
if (ptr == NULL) {
if (!ptr) {
SDL_OutOfMemory();
break;
}
@@ -78,18 +78,18 @@ static char *search_path_for_binary(const char *bin)
char *start = envr;
char *ptr;
if (envr == NULL) {
if (!envr) {
SDL_SetError("No $PATH set");
return NULL;
}
envr = SDL_strdup(envr);
if (envr == NULL) {
if (!envr) {
SDL_OutOfMemory();
return NULL;
}
SDL_assert(bin != NULL);
SDL_assert(bin);
alloc_size = SDL_strlen(bin) + SDL_strlen(envr) + 2;
exe = (char *)SDL_malloc(alloc_size);
@@ -110,7 +110,7 @@ static char *search_path_for_binary(const char *bin)
}
}
start = ptr + 1; /* start points to beginning of next element. */
} while (ptr != NULL);
} while (ptr);
SDL_free(envr);
SDL_free(exe);
@@ -130,7 +130,7 @@ char *SDL_GetBasePath(void)
const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
if (sysctl(mib, SDL_arraysize(mib), fullpath, &buflen, NULL, 0) != -1) {
retval = SDL_strdup(fullpath);
if (retval == NULL) {
if (!retval) {
SDL_OutOfMemory();
return NULL;
}
@@ -144,13 +144,13 @@ char *SDL_GetBasePath(void)
if (sysctl(mib, 4, NULL, &len, NULL, 0) != -1) {
char *exe, *pwddst;
char *realpathbuf = (char *)SDL_malloc(PATH_MAX + 1);
if (realpathbuf == NULL) {
if (!realpathbuf) {
SDL_OutOfMemory();
return NULL;
}
cmdline = SDL_malloc(len);
if (cmdline == NULL) {
if (!cmdline) {
SDL_free(realpathbuf);
SDL_OutOfMemory();
return NULL;
@@ -172,7 +172,7 @@ char *SDL_GetBasePath(void)
}
if (exe) {
if (pwddst == NULL) {
if (!pwddst) {
if (realpath(exe, realpathbuf) != NULL) {
retval = realpathbuf;
}
@@ -188,7 +188,7 @@ char *SDL_GetBasePath(void)
}
}
if (retval == NULL) {
if (!retval) {
SDL_free(realpathbuf);
}
@@ -197,7 +197,7 @@ char *SDL_GetBasePath(void)
#endif
/* is a Linux-style /proc filesystem available? */
if (retval == NULL && (access("/proc", F_OK) == 0)) {
if (!retval && (access("/proc", F_OK) == 0)) {
/* !!! FIXME: after 2.0.6 ships, let's delete this code and just
use the /proc/%llu version. There's no reason to have
two copies of this plus all the #ifdefs. --ryan. */
@@ -209,7 +209,7 @@ char *SDL_GetBasePath(void)
retval = readSymLink("/proc/self/path/a.out");
#else
retval = readSymLink("/proc/self/exe"); /* linux. */
if (retval == NULL) {
if (!retval) {
/* older kernels don't have /proc/self ... try PID version... */
char path[64];
const int rc = SDL_snprintf(path, sizeof(path),
@@ -225,9 +225,9 @@ char *SDL_GetBasePath(void)
#ifdef __SOLARIS__ /* try this as a fallback if /proc didn't pan out */
if (!retval) {
const char *path = getexecname();
if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
if ((path) && (path[0] == '/')) { /* must be absolute path... */
retval = SDL_strdup(path);
if (retval == NULL) {
if (!retval) {
SDL_OutOfMemory();
return NULL;
}
@@ -237,9 +237,9 @@ char *SDL_GetBasePath(void)
/* If we had access to argv[0] here, we could check it for a path,
or troll through $PATH looking for it, too. */
if (retval != NULL) { /* chop off filename. */
if (retval) { /* chop off filename. */
char *ptr = SDL_strrchr(retval, '/');
if (ptr != NULL) {
if (ptr) {
*(ptr + 1) = '\0';
} else { /* shouldn't happen, but just in case... */
SDL_free(retval);
@@ -247,10 +247,10 @@ char *SDL_GetBasePath(void)
}
}
if (retval != NULL) {
if (retval) {
/* try to shrink buffer... */
char *ptr = (char *)SDL_realloc(retval, SDL_strlen(retval) + 1);
if (ptr != NULL) {
if (ptr) {
retval = ptr; /* oh well if it failed. */
}
}
@@ -273,18 +273,18 @@ char *SDL_GetPrefPath(const char *org, const char *app)
char *ptr = NULL;
size_t len = 0;
if (app == NULL) {
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (org == NULL) {
if (!org) {
org = "";
}
if (envr == NULL) {
if (!envr) {
/* You end up with "$HOME/.local/share/Game Name 2" */
envr = SDL_getenv("HOME");
if (envr == NULL) {
if (!envr) {
/* we could take heroic measures with /etc/passwd, but oh well. */
SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
return NULL;
@@ -301,7 +301,7 @@ char *SDL_GetPrefPath(const char *org, const char *app)
len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
retval = (char *)SDL_malloc(len);
if (retval == NULL) {
if (!retval) {
SDL_OutOfMemory();
return NULL;
}
@@ -372,15 +372,15 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
home_dir = SDL_getenv ("HOME");
if (home_dir == NULL)
if (!home_dir)
goto error;
config_home = SDL_getenv ("XDG_CONFIG_HOME");
if (config_home == NULL || config_home[0] == 0)
if (!config_home || config_home[0] == 0)
{
l = SDL_strlen (home_dir) + SDL_strlen ("/.config/user-dirs.dirs") + 1;
config_file = (char*) SDL_malloc (l);
if (config_file == NULL)
if (!config_file)
goto error;
SDL_strlcpy (config_file, home_dir, l);
@@ -390,7 +390,7 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
{
l = SDL_strlen (config_home) + SDL_strlen ("/user-dirs.dirs") + 1;
config_file = (char*) SDL_malloc (l);
if (config_file == NULL)
if (!config_file)
goto error;
SDL_strlcpy (config_file, config_home, l);
@@ -399,7 +399,7 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
file = fopen (config_file, "r");
SDL_free (config_file);
if (file == NULL)
if (!file)
goto error;
user_dir = NULL;
@@ -452,7 +452,7 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
{
l = SDL_strlen (home_dir) + 1 + SDL_strlen (p) + 1;
user_dir = (char*) SDL_malloc (l);
if (user_dir == NULL)
if (!user_dir)
goto error2;
SDL_strlcpy (user_dir, home_dir, l);
@@ -461,7 +461,7 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
else
{
user_dir = (char*) SDL_malloc (SDL_strlen (p) + 1);
if (user_dir == NULL)
if (!user_dir)
goto error2;
*user_dir = 0;
@@ -493,12 +493,12 @@ static char *xdg_user_dir_lookup (const char *type)
char *dir, *home_dir, *user_dir;
dir = xdg_user_dir_lookup_with_fallback(type, NULL);
if (dir != NULL)
if (dir)
return dir;
home_dir = SDL_getenv("HOME");
if (home_dir == NULL)
if (!home_dir)
return NULL;
/* Special case desktop for historical compatibility */
@@ -506,7 +506,7 @@ static char *xdg_user_dir_lookup (const char *type)
{
user_dir = (char*) SDL_malloc(SDL_strlen(home_dir) +
SDL_strlen("/Desktop") + 1);
if (user_dir == NULL)
if (!user_dir)
return NULL;
strcpy(user_dir, home_dir);

View File

@@ -48,11 +48,11 @@ char *SDL_GetPrefPath(const char *org, const char *app)
char *ptr = NULL;
size_t len = 0;
if (app == NULL) {
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (org == NULL) {
if (!org) {
org = "";
}
@@ -60,7 +60,7 @@ char *SDL_GetPrefPath(const char *org, const char *app)
len += SDL_strlen(org) + SDL_strlen(app) + 3;
retval = (char *)SDL_malloc(len);
if (retval == NULL) {
if (!retval) {
SDL_OutOfMemory();
return NULL;
}

View File

@@ -51,7 +51,7 @@ char *SDL_GetBasePath(void)
while (SDL_TRUE) {
void *ptr = SDL_realloc(path, buflen * sizeof(WCHAR));
if (ptr == NULL) {
if (!ptr) {
SDL_free(path);
SDL_OutOfMemory();
return NULL;
@@ -108,11 +108,11 @@ char *SDL_GetPrefPath(const char *org, const char *app)
size_t new_wpath_len = 0;
BOOL api_result = FALSE;
if (app == NULL) {
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (org == NULL) {
if (!org) {
org = "";
}
@@ -122,13 +122,13 @@ char *SDL_GetPrefPath(const char *org, const char *app)
}
worg = WIN_UTF8ToStringW(org);
if (worg == NULL) {
if (!worg) {
SDL_OutOfMemory();
return NULL;
}
wapp = WIN_UTF8ToStringW(app);
if (wapp == NULL) {
if (!wapp) {
SDL_free(worg);
SDL_OutOfMemory();
return NULL;

View File

@@ -106,7 +106,7 @@ SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
}
const wchar_t *ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
if (ucs2Path == NULL) {
if (!ucs2Path) {
return NULL;
}
@@ -123,14 +123,14 @@ SDL_GetBasePath(void)
size_t destPathLen;
char *destPath = NULL;
if (srcPath == NULL) {
if (!srcPath) {
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
return NULL;
}
destPathLen = SDL_strlen(srcPath) + 2;
destPath = (char *)SDL_malloc(destPathLen);
if (destPath == NULL) {
if (!destPath) {
SDL_OutOfMemory();
return NULL;
}
@@ -156,16 +156,16 @@ SDL_GetPrefPath(const char *org, const char *app)
size_t new_wpath_len = 0;
BOOL api_result = FALSE;
if (app == NULL) {
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (org == NULL) {
if (!org) {
org = "";
}
srcPath = SDL_WinRTGetFSPathUNICODE(SDL_WINRT_PATH_LOCAL_FOLDER);
if (srcPath == NULL) {
if (!srcPath) {
SDL_SetError("Unable to find a source path");
return NULL;
}
@@ -177,13 +177,13 @@ SDL_GetPrefPath(const char *org, const char *app)
SDL_wcslcpy(path, srcPath, SDL_arraysize(path));
worg = WIN_UTF8ToString(org);
if (worg == NULL) {
if (!worg) {
SDL_OutOfMemory();
return NULL;
}
wapp = WIN_UTF8ToString(app);
if (wapp == NULL) {
if (!wapp) {
SDL_free(worg);
SDL_OutOfMemory();
return NULL;