Pointer as bool (libsdl-org#7214)

main
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

@ -385,7 +385,7 @@ main(int argc, char *argv[])
/* Initialize test framework */ /* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO); state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO);
if (state == NULL) { if (!state) {
return 1; return 1;
} }
@ -448,7 +448,7 @@ main(int argc, char *argv[])
/* Create the windows, initialize the renderers, and load the textures */ /* Create the windows, initialize the renderers, and load the textures */
sprites = sprites =
(SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites)); (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
if (sprites == NULL) { if (!sprites) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2); quit(2);
} }
@ -463,7 +463,7 @@ main(int argc, char *argv[])
soundname = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav"); soundname = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
if (soundname == NULL) { if (!soundname) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
quit(1); quit(1);
} }

View File

@ -10,7 +10,7 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
window = SDL_CreateWindow("Hello SDL", 640, 480, 0); window = SDL_CreateWindow("Hello SDL", 640, 480, 0);
if (window == NULL) { if (!window) {
SDL_Log("could not create window: %s\n", SDL_GetError()); SDL_Log("could not create window: %s\n", SDL_GetError());
return 1; return 1;
} }

View File

@ -557,7 +557,7 @@ int SDL_GetVersion(SDL_version *ver)
static SDL_bool check_hint = SDL_TRUE; static SDL_bool check_hint = SDL_TRUE;
static SDL_bool legacy_version = SDL_FALSE; static SDL_bool legacy_version = SDL_FALSE;
if (ver == NULL) { if (!ver) {
return SDL_InvalidParamError("ver"); return SDL_InvalidParamError("ver");
} }

View File

@ -106,11 +106,11 @@ static void SDL_GenerateAssertionReport(void)
const SDL_AssertData *item = triggered_assertions; const SDL_AssertData *item = triggered_assertions;
/* only do this if the app hasn't assigned an assertion handler. */ /* only do this if the app hasn't assigned an assertion handler. */
if ((item != NULL) && (assertion_handler != SDL_PromptAssertion)) { if ((item) && (assertion_handler != SDL_PromptAssertion)) {
debug_print("\n\nSDL assertion report.\n"); debug_print("\n\nSDL assertion report.\n");
debug_print("All SDL assertions between last init/quit:\n\n"); debug_print("All SDL assertions between last init/quit:\n\n");
while (item != NULL) { while (item) {
debug_print( debug_print(
"'%s'\n" "'%s'\n"
" * %s (%s:%d)\n" " * %s (%s:%d)\n"
@ -198,7 +198,7 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v
/* let env. variable override, so unit tests won't block in a GUI. */ /* let env. variable override, so unit tests won't block in a GUI. */
envr = SDL_getenv("SDL_ASSERT"); envr = SDL_getenv("SDL_ASSERT");
if (envr != NULL) { if (envr) {
if (message != stack_buf) { if (message != stack_buf) {
SDL_free(message); SDL_free(message);
} }
@ -334,9 +334,9 @@ SDL_AssertState SDL_ReportAssertion(SDL_AssertData *data, const char *func, cons
#ifndef SDL_THREADS_DISABLED #ifndef SDL_THREADS_DISABLED
static SDL_SpinLock spinlock = 0; static SDL_SpinLock spinlock = 0;
SDL_AtomicLock(&spinlock); SDL_AtomicLock(&spinlock);
if (assertion_mutex == NULL) { /* never called SDL_Init()? */ if (!assertion_mutex) { /* never called SDL_Init()? */
assertion_mutex = SDL_CreateMutex(); assertion_mutex = SDL_CreateMutex();
if (assertion_mutex == NULL) { if (!assertion_mutex) {
SDL_AtomicUnlock(&spinlock); SDL_AtomicUnlock(&spinlock);
return SDL_ASSERTION_IGNORE; /* oh well, I guess. */ return SDL_ASSERTION_IGNORE; /* oh well, I guess. */
} }
@ -401,7 +401,7 @@ void SDL_AssertionsQuit(void)
#if SDL_ASSERT_LEVEL > 0 #if SDL_ASSERT_LEVEL > 0
SDL_GenerateAssertionReport(); SDL_GenerateAssertionReport();
#ifndef SDL_THREADS_DISABLED #ifndef SDL_THREADS_DISABLED
if (assertion_mutex != NULL) { if (assertion_mutex) {
SDL_DestroyMutex(assertion_mutex); SDL_DestroyMutex(assertion_mutex);
assertion_mutex = NULL; assertion_mutex = NULL;
} }
@ -429,7 +429,7 @@ void SDL_ResetAssertionReport(void)
{ {
SDL_AssertData *next = NULL; SDL_AssertData *next = NULL;
SDL_AssertData *item; SDL_AssertData *item;
for (item = triggered_assertions; item != NULL; item = next) { for (item = triggered_assertions; item; item = next) {
next = (SDL_AssertData *)item->next; next = (SDL_AssertData *)item->next;
item->always_ignore = SDL_FALSE; item->always_ignore = SDL_FALSE;
item->trigger_count = 0; item->trigger_count = 0;
@ -446,7 +446,7 @@ SDL_AssertionHandler SDL_GetDefaultAssertionHandler(void)
SDL_AssertionHandler SDL_GetAssertionHandler(void **userdata) SDL_AssertionHandler SDL_GetAssertionHandler(void **userdata)
{ {
if (userdata != NULL) { if (userdata) {
*userdata = assertion_userdata; *userdata = assertion_userdata;
} }
return assertion_handler; return assertion_handler;

View File

@ -27,7 +27,7 @@
int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
/* Ignore call if invalid format pointer was passed */ /* Ignore call if invalid format pointer was passed */
if (fmt != NULL) { if (fmt) {
va_list ap; va_list ap;
int result; int result;
SDL_error *error = SDL_GetErrBuf(); SDL_error *error = SDL_GetErrBuf();

View File

@ -26,7 +26,7 @@ int SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)
static const char k_rgchHexToASCII[] = "0123456789abcdef"; static const char k_rgchHexToASCII[] = "0123456789abcdef";
int i; int i;
if (pszGUID == NULL) { if (!pszGUID) {
return SDL_InvalidParamError("pszGUID"); return SDL_InvalidParamError("pszGUID");
} }
if (cbGUID <= 0) { if (cbGUID <= 0) {

View File

@ -53,13 +53,13 @@ SDL_HashTable *SDL_CreateHashTable(void *data, const Uint32 num_buckets, const S
} }
table = (SDL_HashTable *) SDL_calloc(1, sizeof (SDL_HashTable)); table = (SDL_HashTable *) SDL_calloc(1, sizeof (SDL_HashTable));
if (table == NULL) { if (!table) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
table->table = (SDL_HashItem **) SDL_calloc(num_buckets, sizeof (SDL_HashItem *)); table->table = (SDL_HashItem **) SDL_calloc(num_buckets, sizeof (SDL_HashItem *));
if (table->table == NULL) { if (!table->table) {
SDL_free(table); SDL_free(table);
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
@ -91,7 +91,7 @@ SDL_bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const vo
// !!! FIXME: grow and rehash table if it gets too saturated. // !!! FIXME: grow and rehash table if it gets too saturated.
item = (SDL_HashItem *) SDL_malloc(sizeof (SDL_HashItem)); item = (SDL_HashItem *) SDL_malloc(sizeof (SDL_HashItem));
if (item == NULL) { if (!item) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;
} }
@ -110,9 +110,9 @@ SDL_bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const
void *data = table->data; void *data = table->data;
SDL_HashItem *i; SDL_HashItem *i;
for (i = table->table[hash]; i != NULL; i = i->next) { for (i = table->table[hash]; i; i = i->next) {
if (table->keymatch(key, i->key, data)) { if (table->keymatch(key, i->key, data)) {
if (_value != NULL) { if (_value) {
*_value = i->value; *_value = i->value;
} }
return SDL_TRUE; return SDL_TRUE;
@ -129,9 +129,9 @@ SDL_bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key)
SDL_HashItem *prev = NULL; SDL_HashItem *prev = NULL;
void *data = table->data; void *data = table->data;
for (item = table->table[hash]; item != NULL; item = item->next) { for (item = table->table[hash]; item; item = item->next) {
if (table->keymatch(key, item->key, data)) { if (table->keymatch(key, item->key, data)) {
if (prev != NULL) { if (prev) {
prev->next = item->next; prev->next = item->next;
} else { } else {
table->table[hash] = item->next; table->table[hash] = item->next;
@ -152,7 +152,7 @@ SDL_bool SDL_IterateHashTableKey(const SDL_HashTable *table, const void *key, co
{ {
SDL_HashItem *item = *iter ? ((SDL_HashItem *) *iter)->next : table->table[calc_hash(table, key)]; SDL_HashItem *item = *iter ? ((SDL_HashItem *) *iter)->next : table->table[calc_hash(table, key)];
while (item != NULL) { while (item) {
if (table->keymatch(key, item->key, table->data)) { if (table->keymatch(key, item->key, table->data)) {
*_value = item->value; *_value = item->value;
*iter = item; *iter = item;
@ -172,10 +172,10 @@ SDL_bool SDL_IterateHashTable(const SDL_HashTable *table, const void **_key, con
SDL_HashItem *item = (SDL_HashItem *) *iter; SDL_HashItem *item = (SDL_HashItem *) *iter;
Uint32 idx = 0; Uint32 idx = 0;
if (item != NULL) { if (item) {
const SDL_HashItem *orig = item; const SDL_HashItem *orig = item;
item = item->next; item = item->next;
if (item == NULL) { if (!item) {
idx = calc_hash(table, orig->key) + 1; // !!! FIXME: we probably shouldn't rehash each time. idx = calc_hash(table, orig->key) + 1; // !!! FIXME: we probably shouldn't rehash each time.
} }
} }
@ -184,7 +184,7 @@ SDL_bool SDL_IterateHashTable(const SDL_HashTable *table, const void **_key, con
item = table->table[idx++]; // skip empty buckets... item = table->table[idx++]; // skip empty buckets...
} }
if (item == NULL) { // no more matches? if (!item) { // no more matches?
*_key = NULL; *_key = NULL;
*iter = NULL; *iter = NULL;
return SDL_FALSE; return SDL_FALSE;
@ -199,12 +199,12 @@ SDL_bool SDL_IterateHashTable(const SDL_HashTable *table, const void **_key, con
SDL_bool SDL_HashTableEmpty(SDL_HashTable *table) SDL_bool SDL_HashTableEmpty(SDL_HashTable *table)
{ {
if (table != NULL) { if (table) {
Uint32 i; Uint32 i;
for (i = 0; i < table->table_len; i++) { for (i = 0; i < table->table_len; i++) {
SDL_HashItem *item = table->table[i]; SDL_HashItem *item = table->table[i];
if (item != NULL) { if (item) {
return SDL_FALSE; return SDL_FALSE;
} }
} }
@ -214,13 +214,13 @@ SDL_bool SDL_HashTableEmpty(SDL_HashTable *table)
void SDL_DestroyHashTable(SDL_HashTable *table) void SDL_DestroyHashTable(SDL_HashTable *table)
{ {
if (table != NULL) { if (table) {
void *data = table->data; void *data = table->data;
Uint32 i; Uint32 i;
for (i = 0; i < table->table_len; i++) { for (i = 0; i < table->table_len; i++) {
SDL_HashItem *item = table->table[i]; SDL_HashItem *item = table->table[i];
while (item != NULL) { while (item) {
SDL_HashItem *next = item->next; SDL_HashItem *next = item->next;
table->nuke(item->key, item->value, data); table->nuke(item->key, item->value, data);
SDL_free(item); SDL_free(item);

View File

@ -49,7 +49,7 @@ SDL_bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPr
SDL_Hint *hint; SDL_Hint *hint;
SDL_HintWatch *entry; SDL_HintWatch *entry;
if (name == NULL) { if (!name) {
return SDL_FALSE; return SDL_FALSE;
} }
@ -64,7 +64,7 @@ SDL_bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPr
return SDL_FALSE; return SDL_FALSE;
} }
if (hint->value != value && if (hint->value != value &&
(value == NULL || !hint->value || SDL_strcmp(hint->value, value) != 0)) { (!value || !hint->value || SDL_strcmp(hint->value, value) != 0)) {
char *old_value = hint->value; char *old_value = hint->value;
hint->value = value ? SDL_strdup(value) : NULL; hint->value = value ? SDL_strdup(value) : NULL;
@ -85,7 +85,7 @@ SDL_bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPr
/* Couldn't find the hint, add a new one */ /* Couldn't find the hint, add a new one */
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
if (hint == NULL) { if (!hint) {
return SDL_FALSE; return SDL_FALSE;
} }
hint->name = SDL_strdup(name); hint->name = SDL_strdup(name);
@ -103,16 +103,16 @@ SDL_bool SDL_ResetHint(const char *name)
SDL_Hint *hint; SDL_Hint *hint;
SDL_HintWatch *entry; SDL_HintWatch *entry;
if (name == NULL) { if (!name) {
return SDL_FALSE; return SDL_FALSE;
} }
env = SDL_getenv(name); env = SDL_getenv(name);
for (hint = SDL_hints; hint; hint = hint->next) { for (hint = SDL_hints; hint; hint = hint->next) {
if (SDL_strcmp(name, hint->name) == 0) { if (SDL_strcmp(name, hint->name) == 0) {
if ((env == NULL && hint->value != NULL) || if ((!env && hint->value) ||
(env != NULL && hint->value == NULL) || (env && !hint->value) ||
(env != NULL && SDL_strcmp(env, hint->value) != 0)) { (env && SDL_strcmp(env, hint->value) != 0)) {
for (entry = hint->callbacks; entry;) { for (entry = hint->callbacks; entry;) {
/* Save the next entry in case this one is deleted */ /* Save the next entry in case this one is deleted */
SDL_HintWatch *next = entry->next; SDL_HintWatch *next = entry->next;
@ -137,9 +137,9 @@ void SDL_ResetHints(void)
for (hint = SDL_hints; hint; hint = hint->next) { for (hint = SDL_hints; hint; hint = hint->next) {
env = SDL_getenv(hint->name); env = SDL_getenv(hint->name);
if ((env == NULL && hint->value != NULL) || if ((!env && hint->value) ||
(env != NULL && hint->value == NULL) || (env && !hint->value) ||
(env != NULL && SDL_strcmp(env, hint->value) != 0)) { (env && SDL_strcmp(env, hint->value) != 0)) {
for (entry = hint->callbacks; entry;) { for (entry = hint->callbacks; entry;) {
/* Save the next entry in case this one is deleted */ /* Save the next entry in case this one is deleted */
SDL_HintWatch *next = entry->next; SDL_HintWatch *next = entry->next;
@ -166,7 +166,7 @@ const char *SDL_GetHint(const char *name)
env = SDL_getenv(name); env = SDL_getenv(name);
for (hint = SDL_hints; hint; hint = hint->next) { for (hint = SDL_hints; hint; hint = hint->next) {
if (SDL_strcmp(name, hint->name) == 0) { if (SDL_strcmp(name, hint->name) == 0) {
if (env == NULL || hint->priority == SDL_HINT_OVERRIDE) { if (!env || hint->priority == SDL_HINT_OVERRIDE) {
return hint->value; return hint->value;
} }
break; break;
@ -177,7 +177,7 @@ const char *SDL_GetHint(const char *name)
int SDL_GetStringInteger(const char *value, int default_value) int SDL_GetStringInteger(const char *value, int default_value)
{ {
if (value == NULL || !*value) { if (!value || !*value) {
return default_value; return default_value;
} }
if (*value == '0' || SDL_strcasecmp(value, "false") == 0) { if (*value == '0' || SDL_strcasecmp(value, "false") == 0) {
@ -194,7 +194,7 @@ int SDL_GetStringInteger(const char *value, int default_value)
SDL_bool SDL_GetStringBoolean(const char *value, SDL_bool default_value) SDL_bool SDL_GetStringBoolean(const char *value, SDL_bool default_value)
{ {
if (value == NULL || !*value) { if (!value || !*value) {
return default_value; return default_value;
} }
if (*value == '0' || SDL_strcasecmp(value, "false") == 0) { if (*value == '0' || SDL_strcasecmp(value, "false") == 0) {
@ -215,7 +215,7 @@ int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userd
SDL_HintWatch *entry; SDL_HintWatch *entry;
const char *value; const char *value;
if (name == NULL || !*name) { if (!name || !*name) {
return SDL_InvalidParamError("name"); return SDL_InvalidParamError("name");
} }
if (!callback) { if (!callback) {
@ -225,7 +225,7 @@ int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userd
SDL_DelHintCallback(name, callback, userdata); SDL_DelHintCallback(name, callback, userdata);
entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry)); entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
if (entry == NULL) { if (!entry) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
entry->callback = callback; entry->callback = callback;
@ -236,10 +236,10 @@ int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userd
break; break;
} }
} }
if (hint == NULL) { if (!hint) {
/* Need to add a hint entry for this watcher */ /* Need to add a hint entry for this watcher */
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
if (hint == NULL) { if (!hint) {
SDL_free(entry); SDL_free(entry);
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }

View File

@ -27,7 +27,7 @@ int SDL_ListAdd(SDL_ListNode **head, void *ent)
{ {
SDL_ListNode *node = SDL_malloc(sizeof(*node)); SDL_ListNode *node = SDL_malloc(sizeof(*node));
if (node == NULL) { if (!node) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -43,7 +43,7 @@ void SDL_ListPop(SDL_ListNode **head, void **ent)
SDL_ListNode **ptr = head; SDL_ListNode **ptr = head;
/* Invalid or empty */ /* Invalid or empty */
if (head == NULL || *head == NULL) { if (!head || !*head) {
return; return;
} }

View File

@ -112,7 +112,7 @@ static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
void SDL_InitLog(void) void SDL_InitLog(void)
{ {
if (log_function_mutex == NULL) { if (!log_function_mutex) {
/* if this fails we'll try to continue without it. */ /* if this fails we'll try to continue without it. */
log_function_mutex = SDL_CreateMutex(); log_function_mutex = SDL_CreateMutex();
} }
@ -305,7 +305,7 @@ void SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va
return; return;
} }
if (log_function_mutex == NULL) { if (!log_function_mutex) {
/* this mutex creation can race if you log from two threads at startup. You should have called SDL_Init first! */ /* this mutex creation can race if you log from two threads at startup. You should have called SDL_Init first! */
log_function_mutex = SDL_CreateMutex(); log_function_mutex = SDL_CreateMutex();
} }
@ -323,7 +323,7 @@ void SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va
if (len >= sizeof(stack_buf) && SDL_size_add_overflow(len, 1, &len_plus_term) == 0) { if (len >= sizeof(stack_buf) && SDL_size_add_overflow(len, 1, &len_plus_term) == 0) {
/* Allocate exactly what we need, including the zero-terminator */ /* Allocate exactly what we need, including the zero-terminator */
message = (char *)SDL_malloc(len_plus_term); message = (char *)SDL_malloc(len_plus_term);
if (message == NULL) { if (!message) {
return; return;
} }
va_copy(aq, ap); va_copy(aq, ap);
@ -459,7 +459,7 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
{ {
FILE *pFile; FILE *pFile;
pFile = fopen("SDL_Log.txt", "a"); pFile = fopen("SDL_Log.txt", "a");
if (pFile != NULL) { if (pFile) {
(void)fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message); (void)fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
(void)fclose(pFile); (void)fclose(pFile);
} }
@ -468,7 +468,7 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
{ {
FILE *pFile; FILE *pFile;
pFile = fopen("ux0:/data/SDL_Log.txt", "a"); pFile = fopen("ux0:/data/SDL_Log.txt", "a");
if (pFile != NULL) { if (pFile) {
(void)fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message); (void)fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
(void)fclose(pFile); (void)fclose(pFile);
} }
@ -477,7 +477,7 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
{ {
FILE *pFile; FILE *pFile;
pFile = fopen("sdmc:/3ds/SDL_Log.txt", "a"); pFile = fopen("sdmc:/3ds/SDL_Log.txt", "a");
if (pFile != NULL) { if (pFile) {
(void)fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message); (void)fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
(void)fclose(pFile); (void)fclose(pFile);
} }

View File

@ -63,7 +63,7 @@ SDL_bool SDL_AtomicTryLock(SDL_SpinLock *lock)
/* Terrible terrible damage */ /* Terrible terrible damage */
static SDL_Mutex *_spinlock_mutex; static SDL_Mutex *_spinlock_mutex;
if (_spinlock_mutex == NULL) { if (!_spinlock_mutex) {
/* Race condition on first lock... */ /* Race condition on first lock... */
_spinlock_mutex = SDL_CreateMutex(); _spinlock_mutex = SDL_CreateMutex();
} }

View File

@ -139,7 +139,7 @@ static int GetDefaultSampleFramesFromFreq(const int freq)
void OnAudioStreamCreated(SDL_AudioStream *stream) void OnAudioStreamCreated(SDL_AudioStream *stream)
{ {
SDL_assert(stream != NULL); SDL_assert(stream);
// NOTE that you can create an audio stream without initializing the audio subsystem, // NOTE that you can create an audio stream without initializing the audio subsystem,
// but it will not be automatically destroyed during a later call to SDL_Quit! // but it will not be automatically destroyed during a later call to SDL_Quit!
@ -159,7 +159,7 @@ void OnAudioStreamCreated(SDL_AudioStream *stream)
void OnAudioStreamDestroy(SDL_AudioStream *stream) void OnAudioStreamDestroy(SDL_AudioStream *stream)
{ {
SDL_assert(stream != NULL); SDL_assert(stream);
// NOTE that you can create an audio stream without initializing the audio subsystem, // NOTE that you can create an audio stream without initializing the audio subsystem,
// but it will not be automatically destroyed during a later call to SDL_Quit! // but it will not be automatically destroyed during a later call to SDL_Quit!
@ -207,8 +207,8 @@ static void UpdateAudioStreamFormatsPhysical(SDL_AudioDevice *device)
spec.format = SDL_AUDIO_F32; // mixing and postbuf operates in float32 format. spec.format = SDL_AUDIO_F32; // mixing and postbuf operates in float32 format.
} }
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = logdev->next) { for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev; logdev = logdev->next) {
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) { for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = stream->next_binding) {
// set the proper end of the stream to the device's format. // set the proper end of the stream to the device's format.
// SDL_SetAudioStreamFormat does a ton of validation just to memcpy an audiospec. // SDL_SetAudioStreamFormat does a ton of validation just to memcpy an audiospec.
SDL_LockMutex(stream->lock); SDL_LockMutex(stream->lock);
@ -441,7 +441,7 @@ static void DestroyLogicalAudioDevice(SDL_LogicalAudioDevice *logdev)
// unbind any still-bound streams... // unbind any still-bound streams...
SDL_AudioStream *next; SDL_AudioStream *next;
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = next) { for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = next) {
SDL_LockMutex(stream->lock); SDL_LockMutex(stream->lock);
next = stream->next_binding; next = stream->next_binding;
stream->next_binding = NULL; stream->next_binding = NULL;
@ -463,7 +463,7 @@ static void DestroyPhysicalAudioDevice(SDL_AudioDevice *device)
// Destroy any logical devices that still exist... // Destroy any logical devices that still exist...
SDL_LockMutex(device->lock); // don't use ObtainPhysicalAudioDeviceObj because we don't want to change refcounts while destroying. SDL_LockMutex(device->lock); // don't use ObtainPhysicalAudioDeviceObj because we don't want to change refcounts while destroying.
while (device->logical_devices != NULL) { while (device->logical_devices) {
DestroyLogicalAudioDevice(device->logical_devices); DestroyLogicalAudioDevice(device->logical_devices);
} }
SDL_UnlockMutex(device->lock); // don't use ReleaseAudioDevice because we don't want to change refcounts while destroying. SDL_UnlockMutex(device->lock); // don't use ReleaseAudioDevice because we don't want to change refcounts while destroying.
@ -500,7 +500,7 @@ void RefPhysicalAudioDevice(SDL_AudioDevice *device)
static SDL_AudioDevice *CreatePhysicalAudioDevice(const char *name, SDL_bool iscapture, const SDL_AudioSpec *spec, void *handle, SDL_AtomicInt *device_count) static SDL_AudioDevice *CreatePhysicalAudioDevice(const char *name, SDL_bool iscapture, const SDL_AudioSpec *spec, void *handle, SDL_AtomicInt *device_count)
{ {
SDL_assert(name != NULL); SDL_assert(name);
SDL_LockRWLockForReading(current_audio.device_hash_lock); SDL_LockRWLockForReading(current_audio.device_hash_lock);
const int shutting_down = SDL_AtomicGet(&current_audio.shutting_down); const int shutting_down = SDL_AtomicGet(&current_audio.shutting_down);
@ -593,8 +593,8 @@ SDL_AudioDevice *SDL_AddAudioDevice(const SDL_bool iscapture, const char *name,
p->devid = device->instance_id; p->devid = device->instance_id;
p->next = NULL; p->next = NULL;
SDL_LockRWLockForWriting(current_audio.device_hash_lock); SDL_LockRWLockForWriting(current_audio.device_hash_lock);
SDL_assert(current_audio.pending_events_tail != NULL); SDL_assert(current_audio.pending_events_tail);
SDL_assert(current_audio.pending_events_tail->next == NULL); SDL_assert(!current_audio.pending_events_tail->next);
current_audio.pending_events_tail->next = p; current_audio.pending_events_tail->next = p;
current_audio.pending_events_tail = p; current_audio.pending_events_tail = p;
SDL_UnlockRWLock(current_audio.device_hash_lock); SDL_UnlockRWLock(current_audio.device_hash_lock);
@ -642,7 +642,7 @@ void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device)
// on default devices, dump any logical devices that explicitly opened this device. Things that opened the system default can stay. // on default devices, dump any logical devices that explicitly opened this device. Things that opened the system default can stay.
// on non-default devices, dump everything. // on non-default devices, dump everything.
// (by "dump" we mean send a REMOVED event; the zombie will keep consuming audio data for these logical devices until explicitly closed.) // (by "dump" we mean send a REMOVED event; the zombie will keep consuming audio data for these logical devices until explicitly closed.)
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = logdev->next) { for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev; logdev = logdev->next) {
if (!is_default_device || !logdev->opened_as_default) { // if opened as a default, leave it on the zombie device for later migration. if (!is_default_device || !logdev->opened_as_default) { // if opened as a default, leave it on the zombie device for later migration.
SDL_PendingAudioDeviceEvent *p = (SDL_PendingAudioDeviceEvent *) SDL_malloc(sizeof (SDL_PendingAudioDeviceEvent)); SDL_PendingAudioDeviceEvent *p = (SDL_PendingAudioDeviceEvent *) SDL_malloc(sizeof (SDL_PendingAudioDeviceEvent));
if (p) { // if this failed, no event for you, but you have deeper problems anyhow. if (p) { // if this failed, no event for you, but you have deeper problems anyhow.
@ -670,8 +670,8 @@ void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device)
if (first_disconnect) { if (first_disconnect) {
if (pending.next) { // NULL if event is disabled or disaster struck. if (pending.next) { // NULL if event is disabled or disaster struck.
SDL_LockRWLockForWriting(current_audio.device_hash_lock); SDL_LockRWLockForWriting(current_audio.device_hash_lock);
SDL_assert(current_audio.pending_events_tail != NULL); SDL_assert(current_audio.pending_events_tail);
SDL_assert(current_audio.pending_events_tail->next == NULL); SDL_assert(!current_audio.pending_events_tail->next);
current_audio.pending_events_tail->next = pending.next; current_audio.pending_events_tail->next = pending.next;
current_audio.pending_events_tail = pending_tail; current_audio.pending_events_tail = pending_tail;
SDL_UnlockRWLock(current_audio.device_hash_lock); SDL_UnlockRWLock(current_audio.device_hash_lock);
@ -817,26 +817,26 @@ int SDL_InitAudio(const char *driver_name)
} }
// Select the proper audio driver // Select the proper audio driver
if (driver_name == NULL) { if (!driver_name) {
driver_name = SDL_GetHint(SDL_HINT_AUDIO_DRIVER); driver_name = SDL_GetHint(SDL_HINT_AUDIO_DRIVER);
} }
SDL_bool initialized = SDL_FALSE; SDL_bool initialized = SDL_FALSE;
SDL_bool tried_to_init = SDL_FALSE; SDL_bool tried_to_init = SDL_FALSE;
if (driver_name != NULL && *driver_name != 0) { if (driver_name && *driver_name != 0) {
char *driver_name_copy = SDL_strdup(driver_name); char *driver_name_copy = SDL_strdup(driver_name);
const char *driver_attempt = driver_name_copy; const char *driver_attempt = driver_name_copy;
if (driver_name_copy == NULL) { if (!driver_name_copy) {
SDL_DestroyRWLock(device_hash_lock); SDL_DestroyRWLock(device_hash_lock);
SDL_DestroyHashTable(device_hash); SDL_DestroyHashTable(device_hash);
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
while (driver_attempt != NULL && *driver_attempt != 0 && !initialized) { while (driver_attempt && *driver_attempt != 0 && !initialized) {
char *driver_attempt_end = SDL_strchr(driver_attempt, ','); char *driver_attempt_end = SDL_strchr(driver_attempt, ',');
if (driver_attempt_end != NULL) { if (driver_attempt_end) {
*driver_attempt_end = '\0'; *driver_attempt_end = '\0';
} }
@ -863,7 +863,7 @@ int SDL_InitAudio(const char *driver_name)
} }
} }
driver_attempt = (driver_attempt_end != NULL) ? (driver_attempt_end + 1) : NULL; driver_attempt = (driver_attempt_end) ? (driver_attempt_end + 1) : NULL;
} }
SDL_free(driver_name_copy); SDL_free(driver_name_copy);
@ -940,7 +940,7 @@ void SDL_QuitAudio(void)
current_audio.impl.DeinitializeStart(); current_audio.impl.DeinitializeStart();
// Destroy any audio streams that still exist... // Destroy any audio streams that still exist...
while (current_audio.existing_streams != NULL) { while (current_audio.existing_streams) {
SDL_DestroyAudioStream(current_audio.existing_streams); SDL_DestroyAudioStream(current_audio.existing_streams);
} }
@ -955,7 +955,7 @@ void SDL_QuitAudio(void)
SDL_UnlockRWLock(current_audio.device_hash_lock); SDL_UnlockRWLock(current_audio.device_hash_lock);
SDL_PendingAudioDeviceEvent *pending_next = NULL; SDL_PendingAudioDeviceEvent *pending_next = NULL;
for (SDL_PendingAudioDeviceEvent *i = pending_events; i != NULL; i = pending_next) { for (SDL_PendingAudioDeviceEvent *i = pending_events; i; i = pending_next) {
pending_next = i->next; pending_next = i->next;
SDL_free(i); SDL_free(i);
} }
@ -1053,7 +1053,7 @@ SDL_bool SDL_OutputAudioThreadIterate(SDL_AudioDevice *device)
SDL_memset(final_mix_buffer, '\0', work_buffer_size); // start with silence. SDL_memset(final_mix_buffer, '\0', work_buffer_size); // start with silence.
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = logdev->next) { for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev; logdev = logdev->next) {
if (SDL_AtomicGet(&logdev->paused)) { if (SDL_AtomicGet(&logdev->paused)) {
continue; // paused? Skip this logical device. continue; // paused? Skip this logical device.
} }
@ -1065,7 +1065,7 @@ SDL_bool SDL_OutputAudioThreadIterate(SDL_AudioDevice *device)
SDL_memset(mix_buffer, '\0', work_buffer_size); // start with silence. SDL_memset(mix_buffer, '\0', work_buffer_size); // start with silence.
} }
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) { for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = stream->next_binding) {
// We should have updated this elsewhere if the format changed! // We should have updated this elsewhere if the format changed!
SDL_assert(AUDIO_SPECS_EQUAL(stream->dst_spec, outspec)); SDL_assert(AUDIO_SPECS_EQUAL(stream->dst_spec, outspec));
@ -1127,7 +1127,7 @@ void SDL_OutputAudioThreadShutdown(SDL_AudioDevice *device)
static int SDLCALL OutputAudioThread(void *devicep) // thread entry point static int SDLCALL OutputAudioThread(void *devicep) // thread entry point
{ {
SDL_AudioDevice *device = (SDL_AudioDevice *)devicep; SDL_AudioDevice *device = (SDL_AudioDevice *)devicep;
SDL_assert(device != NULL); SDL_assert(device);
SDL_assert(!device->iscapture); SDL_assert(!device->iscapture);
SDL_OutputAudioThreadSetup(device); SDL_OutputAudioThreadSetup(device);
@ -1164,7 +1164,7 @@ SDL_bool SDL_CaptureAudioThreadIterate(SDL_AudioDevice *device)
SDL_bool failed = SDL_FALSE; SDL_bool failed = SDL_FALSE;
if (device->logical_devices == NULL) { if (!device->logical_devices) {
device->FlushCapture(device); // nothing wants data, dump anything pending. device->FlushCapture(device); // nothing wants data, dump anything pending.
} else { } else {
// this SHOULD NOT BLOCK, as we are holding a lock right now. Block in WaitCaptureDevice! // this SHOULD NOT BLOCK, as we are holding a lock right now. Block in WaitCaptureDevice!
@ -1172,7 +1172,7 @@ SDL_bool SDL_CaptureAudioThreadIterate(SDL_AudioDevice *device)
if (br < 0) { // uhoh, device failed for some reason! if (br < 0) { // uhoh, device failed for some reason!
failed = SDL_TRUE; failed = SDL_TRUE;
} else if (br > 0) { // queue the new data to each bound stream. } else if (br > 0) { // queue the new data to each bound stream.
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = logdev->next) { for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev; logdev = logdev->next) {
if (SDL_AtomicGet(&logdev->paused)) { if (SDL_AtomicGet(&logdev->paused)) {
continue; // paused? Skip this logical device. continue; // paused? Skip this logical device.
} }
@ -1193,7 +1193,7 @@ SDL_bool SDL_CaptureAudioThreadIterate(SDL_AudioDevice *device)
logdev->postmix(logdev->postmix_userdata, &outspec, device->postmix_buffer, br); logdev->postmix(logdev->postmix_userdata, &outspec, device->postmix_buffer, br);
} }
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) { for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = stream->next_binding) {
// We should have updated this elsewhere if the format changed! // We should have updated this elsewhere if the format changed!
SDL_assert(stream->src_spec.format == (logdev->postmix ? SDL_AUDIO_F32 : device->spec.format)); SDL_assert(stream->src_spec.format == (logdev->postmix ? SDL_AUDIO_F32 : device->spec.format));
SDL_assert(stream->src_spec.channels == device->spec.channels); SDL_assert(stream->src_spec.channels == device->spec.channels);
@ -1233,7 +1233,7 @@ void SDL_CaptureAudioThreadShutdown(SDL_AudioDevice *device)
static int SDLCALL CaptureAudioThread(void *devicep) // thread entry point static int SDLCALL CaptureAudioThread(void *devicep) // thread entry point
{ {
SDL_AudioDevice *device = (SDL_AudioDevice *)devicep; SDL_AudioDevice *device = (SDL_AudioDevice *)devicep;
SDL_assert(device != NULL); SDL_assert(device);
SDL_assert(device->iscapture); SDL_assert(device->iscapture);
SDL_CaptureAudioThreadSetup(device); SDL_CaptureAudioThreadSetup(device);
@ -1261,7 +1261,7 @@ static SDL_AudioDeviceID *GetAudioDevices(int *reqcount, SDL_bool iscapture)
int num_devices = SDL_AtomicGet(iscapture ? &current_audio.capture_device_count : &current_audio.output_device_count); int num_devices = SDL_AtomicGet(iscapture ? &current_audio.capture_device_count : &current_audio.output_device_count);
if (num_devices > 0) { if (num_devices > 0) {
retval = (SDL_AudioDeviceID *) SDL_malloc((num_devices + 1) * sizeof (SDL_AudioDeviceID)); retval = (SDL_AudioDeviceID *) SDL_malloc((num_devices + 1) * sizeof (SDL_AudioDeviceID));
if (retval == NULL) { if (!retval) {
num_devices = 0; num_devices = 0;
SDL_OutOfMemory(); SDL_OutOfMemory();
} else { } else {
@ -1287,7 +1287,7 @@ static SDL_AudioDeviceID *GetAudioDevices(int *reqcount, SDL_bool iscapture)
} }
SDL_UnlockRWLock(current_audio.device_hash_lock); SDL_UnlockRWLock(current_audio.device_hash_lock);
if (reqcount != NULL) { if (reqcount) {
*reqcount = num_devices; *reqcount = num_devices;
} }
@ -1384,7 +1384,7 @@ int SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *
static void ClosePhysicalAudioDevice(SDL_AudioDevice *device) static void ClosePhysicalAudioDevice(SDL_AudioDevice *device)
{ {
SDL_AtomicSet(&device->shutdown, 1); SDL_AtomicSet(&device->shutdown, 1);
if (device->thread != NULL) { if (device->thread) {
SDL_WaitThread(device->thread, NULL); SDL_WaitThread(device->thread, NULL);
device->thread = NULL; device->thread = NULL;
} }
@ -1417,7 +1417,7 @@ void SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid, &device); SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid, &device);
if (logdev) { if (logdev) {
DestroyLogicalAudioDevice(logdev); DestroyLogicalAudioDevice(logdev);
close_physical = (device->logical_devices == NULL); // no more logical devices? Close the physical device, too. close_physical = (!device->logical_devices); // no more logical devices? Close the physical device, too.
} }
// !!! FIXME: we _need_ to release this lock, but doing so can cause a race condition if someone opens a device while we're closing it. // !!! FIXME: we _need_ to release this lock, but doing so can cause a race condition if someone opens a device while we're closing it.
@ -1458,7 +1458,7 @@ static void PrepareAudioFormat(SDL_bool iscapture, SDL_AudioSpec *spec)
spec->freq = iscapture ? DEFAULT_AUDIO_CAPTURE_FREQUENCY : DEFAULT_AUDIO_OUTPUT_FREQUENCY; spec->freq = iscapture ? DEFAULT_AUDIO_CAPTURE_FREQUENCY : DEFAULT_AUDIO_OUTPUT_FREQUENCY;
const char *env = SDL_getenv("SDL_AUDIO_FREQUENCY"); // !!! FIXME: should be a hint? const char *env = SDL_getenv("SDL_AUDIO_FREQUENCY"); // !!! FIXME: should be a hint?
if (env != NULL) { if (env) {
const int val = SDL_atoi(env); const int val = SDL_atoi(env);
if (val > 0) { if (val > 0) {
spec->freq = val; spec->freq = val;
@ -1469,7 +1469,7 @@ static void PrepareAudioFormat(SDL_bool iscapture, SDL_AudioSpec *spec)
if (spec->channels == 0) { if (spec->channels == 0) {
spec->channels = iscapture ? DEFAULT_AUDIO_CAPTURE_CHANNELS : DEFAULT_AUDIO_OUTPUT_CHANNELS;; spec->channels = iscapture ? DEFAULT_AUDIO_CAPTURE_CHANNELS : DEFAULT_AUDIO_OUTPUT_CHANNELS;;
const char *env = SDL_getenv("SDL_AUDIO_CHANNELS"); const char *env = SDL_getenv("SDL_AUDIO_CHANNELS");
if (env != NULL) { if (env) {
const int val = SDL_atoi(env); const int val = SDL_atoi(env);
if (val > 0) { if (val > 0) {
spec->channels = val; spec->channels = val;
@ -1502,7 +1502,7 @@ char *SDL_GetAudioThreadName(SDL_AudioDevice *device, char *buf, size_t buflen)
static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec *inspec) static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec *inspec)
{ {
SDL_assert(!device->currently_opened); SDL_assert(!device->currently_opened);
SDL_assert(device->logical_devices == NULL); SDL_assert(!device->logical_devices);
// Just pretend to open a zombie device. It can still collect logical devices on a default device under the assumption they will all migrate when the default device is officially changed. // Just pretend to open a zombie device. It can still collect logical devices on a default device under the assumption they will all migrate when the default device is officially changed.
if (SDL_AtomicGet(&device->zombie)) { if (SDL_AtomicGet(&device->zombie)) {
@ -1541,14 +1541,14 @@ static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec
// Allocate a scratch audio buffer // Allocate a scratch audio buffer
device->work_buffer = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), device->work_buffer_size); device->work_buffer = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), device->work_buffer_size);
if (device->work_buffer == NULL) { if (!device->work_buffer) {
ClosePhysicalAudioDevice(device); ClosePhysicalAudioDevice(device);
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
if (device->spec.format != SDL_AUDIO_F32) { if (device->spec.format != SDL_AUDIO_F32) {
device->mix_buffer = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), device->work_buffer_size); device->mix_buffer = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), device->work_buffer_size);
if (device->mix_buffer == NULL) { if (!device->mix_buffer) {
ClosePhysicalAudioDevice(device); ClosePhysicalAudioDevice(device);
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -1561,7 +1561,7 @@ static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec
SDL_GetAudioThreadName(device, threadname, sizeof (threadname)); SDL_GetAudioThreadName(device, threadname, sizeof (threadname));
device->thread = SDL_CreateThreadInternal(device->iscapture ? CaptureAudioThread : OutputAudioThread, threadname, stacksize, device); device->thread = SDL_CreateThreadInternal(device->iscapture ? CaptureAudioThread : OutputAudioThread, threadname, stacksize, device);
if (device->thread == NULL) { if (!device->thread) {
ClosePhysicalAudioDevice(device); ClosePhysicalAudioDevice(device);
return SDL_SetError("Couldn't create audio thread"); return SDL_SetError("Couldn't create audio thread");
} }
@ -1672,7 +1672,7 @@ int SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallbac
if (logdev) { if (logdev) {
if (callback && !device->postmix_buffer) { if (callback && !device->postmix_buffer) {
device->postmix_buffer = (float *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), device->work_buffer_size); device->postmix_buffer = (float *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), device->work_buffer_size);
if (device->postmix_buffer == NULL) { if (!device->postmix_buffer) {
retval = SDL_OutOfMemory(); retval = SDL_OutOfMemory();
} }
} }
@ -1682,7 +1682,7 @@ int SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallbac
logdev->postmix_userdata = userdata; logdev->postmix_userdata = userdata;
if (device->iscapture) { if (device->iscapture) {
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) { for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = stream->next_binding) {
// set the proper end of the stream to the device's format. // set the proper end of the stream to the device's format.
// SDL_SetAudioStreamFormat does a ton of validation just to memcpy an audiospec. // SDL_SetAudioStreamFormat does a ton of validation just to memcpy an audiospec.
SDL_LockMutex(stream->lock); SDL_LockMutex(stream->lock);
@ -1709,7 +1709,7 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int
return 0; // nothing to do return 0; // nothing to do
} else if (num_streams < 0) { } else if (num_streams < 0) {
return SDL_InvalidParamError("num_streams"); return SDL_InvalidParamError("num_streams");
} else if (streams == NULL) { } else if (!streams) {
return SDL_InvalidParamError("streams"); return SDL_InvalidParamError("streams");
} else if (!islogical) { } else if (!islogical) {
return SDL_SetError("Audio streams are bound to device ids from SDL_OpenAudioDevice, not raw physical devices"); return SDL_SetError("Audio streams are bound to device ids from SDL_OpenAudioDevice, not raw physical devices");
@ -1726,16 +1726,16 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int
// !!! FIXME: Actually, why do we allow there to be an invalid format, again? // !!! FIXME: Actually, why do we allow there to be an invalid format, again?
// make sure start of list is sane. // make sure start of list is sane.
SDL_assert(!logdev->bound_streams || (logdev->bound_streams->prev_binding == NULL)); SDL_assert(!logdev->bound_streams || (!logdev->bound_streams->prev_binding));
// lock all the streams upfront, so we can verify they aren't bound elsewhere and add them all in one block, as this is intended to add everything or nothing. // lock all the streams upfront, so we can verify they aren't bound elsewhere and add them all in one block, as this is intended to add everything or nothing.
for (int i = 0; i < num_streams; i++) { for (int i = 0; i < num_streams; i++) {
SDL_AudioStream *stream = streams[i]; SDL_AudioStream *stream = streams[i];
if (stream == NULL) { if (!stream) {
retval = SDL_SetError("Stream #%d is NULL", i); retval = SDL_SetError("Stream #%d is NULL", i);
} else { } else {
SDL_LockMutex(stream->lock); SDL_LockMutex(stream->lock);
SDL_assert((stream->bound_device == NULL) == ((stream->prev_binding == NULL) || (stream->next_binding == NULL))); SDL_assert((!stream->bound_device) == ((!stream->prev_binding) || (!stream->next_binding)));
if (stream->bound_device) { if (stream->bound_device) {
retval = SDL_SetError("Stream #%d is already bound to a device", i); retval = SDL_SetError("Stream #%d is already bound to a device", i);
} else if (stream->simplified) { // You can get here if you closed the device instead of destroying the stream. } else if (stream->simplified) { // You can get here if you closed the device instead of destroying the stream.
@ -1830,7 +1830,7 @@ void SDL_UnbindAudioStreams(SDL_AudioStream **streams, int num_streams)
// don't allow unbinding from "simplified" devices (opened with SDL_OpenAudioDeviceStream). Just ignore them. // don't allow unbinding from "simplified" devices (opened with SDL_OpenAudioDeviceStream). Just ignore them.
if (stream && stream->bound_device && !stream->bound_device->simplified) { if (stream && stream->bound_device && !stream->bound_device->simplified) {
if (stream->bound_device->bound_streams == stream) { if (stream->bound_device->bound_streams == stream) {
SDL_assert(stream->prev_binding == NULL); SDL_assert(!stream->prev_binding);
stream->bound_device->bound_streams = stream->next_binding; stream->bound_device->bound_streams = stream->next_binding;
} }
if (stream->prev_binding) { if (stream->prev_binding) {
@ -1887,12 +1887,12 @@ SDL_AudioStream *SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_Au
SDL_AudioStream *stream = NULL; SDL_AudioStream *stream = NULL;
SDL_AudioDevice *device = NULL; SDL_AudioDevice *device = NULL;
SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(logdevid, &device); SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(logdevid, &device);
if (logdev == NULL) { // this shouldn't happen, but just in case. if (!logdev) { // this shouldn't happen, but just in case.
failed = SDL_TRUE; failed = SDL_TRUE;
} else { } else {
SDL_AtomicSet(&logdev->paused, 1); // start the device paused, to match SDL2. SDL_AtomicSet(&logdev->paused, 1); // start the device paused, to match SDL2.
SDL_assert(device != NULL); SDL_assert(device);
const SDL_bool iscapture = device->iscapture; const SDL_bool iscapture = device->iscapture;
if (iscapture) { if (iscapture) {
@ -1960,7 +1960,7 @@ int SDL_GetSilenceValueForFormat(SDL_AudioFormat format)
// called internally by backends when the system default device changes. // called internally by backends when the system default device changes.
void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device) void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)
{ {
if (new_default_device == NULL) { // !!! FIXME: what should we do in this case? Maybe all devices are lost, so there _isn't_ a default? if (!new_default_device) { // !!! FIXME: what should we do in this case? Maybe all devices are lost, so there _isn't_ a default?
return; // uhoh. return; // uhoh.
} }
@ -2007,10 +2007,10 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)
SDL_bool needs_migration = SDL_FALSE; SDL_bool needs_migration = SDL_FALSE;
SDL_zero(spec); SDL_zero(spec);
for (SDL_LogicalAudioDevice *logdev = current_default_device->logical_devices; logdev != NULL; logdev = logdev->next) { for (SDL_LogicalAudioDevice *logdev = current_default_device->logical_devices; logdev; logdev = logdev->next) {
if (logdev->opened_as_default) { if (logdev->opened_as_default) {
needs_migration = SDL_TRUE; needs_migration = SDL_TRUE;
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) { for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = stream->next_binding) {
const SDL_AudioSpec *streamspec = iscapture ? &stream->dst_spec : &stream->src_spec; const SDL_AudioSpec *streamspec = iscapture ? &stream->dst_spec : &stream->src_spec;
if (SDL_AUDIO_BITSIZE(streamspec->format) > SDL_AUDIO_BITSIZE(spec.format)) { if (SDL_AUDIO_BITSIZE(streamspec->format) > SDL_AUDIO_BITSIZE(spec.format)) {
spec.format = streamspec->format; spec.format = streamspec->format;
@ -2036,7 +2036,7 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)
if (needs_migration) { if (needs_migration) {
const SDL_bool spec_changed = !AUDIO_SPECS_EQUAL(current_default_device->spec, new_default_device->spec); const SDL_bool spec_changed = !AUDIO_SPECS_EQUAL(current_default_device->spec, new_default_device->spec);
SDL_LogicalAudioDevice *next = NULL; SDL_LogicalAudioDevice *next = NULL;
for (SDL_LogicalAudioDevice *logdev = current_default_device->logical_devices; logdev != NULL; logdev = next) { for (SDL_LogicalAudioDevice *logdev = current_default_device->logical_devices; logdev; logdev = next) {
next = logdev->next; next = logdev->next;
if (!logdev->opened_as_default) { if (!logdev->opened_as_default) {
@ -2083,7 +2083,7 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)
UpdateAudioStreamFormatsPhysical(current_default_device); UpdateAudioStreamFormatsPhysical(current_default_device);
UpdateAudioStreamFormatsPhysical(new_default_device); UpdateAudioStreamFormatsPhysical(new_default_device);
if (current_default_device->logical_devices == NULL) { // nothing left on the current physical device, close it. if (!current_default_device->logical_devices) { // nothing left on the current physical device, close it.
// !!! FIXME: we _need_ to release this lock, but doing so can cause a race condition if someone opens a device while we're closing it. // !!! FIXME: we _need_ to release this lock, but doing so can cause a race condition if someone opens a device while we're closing it.
RefPhysicalAudioDevice(current_default_device); // hold a temp ref for a moment while we release... RefPhysicalAudioDevice(current_default_device); // hold a temp ref for a moment while we release...
ReleaseAudioDevice(current_default_device); // can't hold the lock or the audio thread will deadlock while we WaitThread it. ReleaseAudioDevice(current_default_device); // can't hold the lock or the audio thread will deadlock while we WaitThread it.
@ -2105,8 +2105,8 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)
if (pending.next) { if (pending.next) {
SDL_LockRWLockForWriting(current_audio.device_hash_lock); SDL_LockRWLockForWriting(current_audio.device_hash_lock);
SDL_assert(current_audio.pending_events_tail != NULL); SDL_assert(current_audio.pending_events_tail);
SDL_assert(current_audio.pending_events_tail->next == NULL); SDL_assert(!current_audio.pending_events_tail->next);
current_audio.pending_events_tail->next = pending.next; current_audio.pending_events_tail->next = pending.next;
current_audio.pending_events_tail = pending_tail; current_audio.pending_events_tail = pending_tail;
SDL_UnlockRWLock(current_audio.device_hash_lock); SDL_UnlockRWLock(current_audio.device_hash_lock);
@ -2173,7 +2173,7 @@ int SDL_AudioDeviceFormatChangedAlreadyLocked(SDL_AudioDevice *device, const SDL
pending_tail = p; pending_tail = p;
} }
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = logdev->next) { for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev; logdev = logdev->next) {
p = (SDL_PendingAudioDeviceEvent *)SDL_malloc(sizeof(SDL_PendingAudioDeviceEvent)); p = (SDL_PendingAudioDeviceEvent *)SDL_malloc(sizeof(SDL_PendingAudioDeviceEvent));
if (p) { // if this failed, no event for you, but you have deeper problems anyhow. if (p) { // if this failed, no event for you, but you have deeper problems anyhow.
p->type = SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED; p->type = SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED;
@ -2186,8 +2186,8 @@ int SDL_AudioDeviceFormatChangedAlreadyLocked(SDL_AudioDevice *device, const SDL
if (pending.next) { if (pending.next) {
SDL_LockRWLockForWriting(current_audio.device_hash_lock); SDL_LockRWLockForWriting(current_audio.device_hash_lock);
SDL_assert(current_audio.pending_events_tail != NULL); SDL_assert(current_audio.pending_events_tail);
SDL_assert(current_audio.pending_events_tail->next == NULL); SDL_assert(!current_audio.pending_events_tail->next);
current_audio.pending_events_tail->next = pending.next; current_audio.pending_events_tail->next = pending.next;
current_audio.pending_events_tail = pending_tail; current_audio.pending_events_tail = pending_tail;
SDL_UnlockRWLock(current_audio.device_hash_lock); SDL_UnlockRWLock(current_audio.device_hash_lock);
@ -2225,7 +2225,7 @@ void SDL_UpdateAudio(void)
SDL_UnlockRWLock(current_audio.device_hash_lock); SDL_UnlockRWLock(current_audio.device_hash_lock);
SDL_PendingAudioDeviceEvent *pending_next = NULL; SDL_PendingAudioDeviceEvent *pending_next = NULL;
for (SDL_PendingAudioDeviceEvent *i = pending_events; i != NULL; i = pending_next) { for (SDL_PendingAudioDeviceEvent *i = pending_events; i; i = pending_next) {
pending_next = i->next; pending_next = i->next;
if (SDL_EventEnabled(i->type)) { if (SDL_EventEnabled(i->type)) {
SDL_Event event; SDL_Event event;

View File

@ -221,8 +221,8 @@ static SDL_bool SDL_IsSupportedChannelCount(const int channels)
void ConvertAudio(int num_frames, const void *src, SDL_AudioFormat src_format, int src_channels, void ConvertAudio(int num_frames, const void *src, SDL_AudioFormat src_format, int src_channels,
void *dst, SDL_AudioFormat dst_format, int dst_channels, void* scratch) void *dst, SDL_AudioFormat dst_format, int dst_channels, void* scratch)
{ {
SDL_assert(src != NULL); SDL_assert(src);
SDL_assert(dst != NULL); SDL_assert(dst);
SDL_assert(SDL_IsSupportedAudioFormat(src_format)); SDL_assert(SDL_IsSupportedAudioFormat(src_format));
SDL_assert(SDL_IsSupportedAudioFormat(dst_format)); SDL_assert(SDL_IsSupportedAudioFormat(dst_format));
SDL_assert(SDL_IsSupportedChannelCount(src_channels)); SDL_assert(SDL_IsSupportedChannelCount(src_channels));
@ -278,7 +278,7 @@ void ConvertAudio(int num_frames, const void *src, SDL_AudioFormat src_format, i
} }
} }
if (scratch == NULL) { if (!scratch) {
scratch = dst; scratch = dst;
} }
@ -313,7 +313,7 @@ void ConvertAudio(int num_frames, const void *src, SDL_AudioFormat src_format, i
SDL_assert(dst_channels <= SDL_arraysize(channel_converters[0])); SDL_assert(dst_channels <= SDL_arraysize(channel_converters[0]));
channel_converter = channel_converters[src_channels - 1][dst_channels - 1]; channel_converter = channel_converters[src_channels - 1][dst_channels - 1];
SDL_assert(channel_converter != NULL); SDL_assert(channel_converter);
// swap in some SIMD versions for a few of these. // swap in some SIMD versions for a few of these.
if (channel_converter == SDL_ConvertStereoToMono) { if (channel_converter == SDL_ConvertStereoToMono) {
@ -408,7 +408,7 @@ SDL_AudioStream *SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_
SDL_SetupAudioResampler(); SDL_SetupAudioResampler();
SDL_AudioStream *retval = (SDL_AudioStream *)SDL_calloc(1, sizeof(SDL_AudioStream)); SDL_AudioStream *retval = (SDL_AudioStream *)SDL_calloc(1, sizeof(SDL_AudioStream));
if (retval == NULL) { if (!retval) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
@ -416,13 +416,13 @@ SDL_AudioStream *SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_
retval->freq_ratio = 1.0f; retval->freq_ratio = 1.0f;
retval->queue = SDL_CreateAudioQueue(4096); retval->queue = SDL_CreateAudioQueue(4096);
if (retval->queue == NULL) { if (!retval->queue) {
SDL_free(retval); SDL_free(retval);
return NULL; return NULL;
} }
retval->lock = SDL_CreateMutex(); retval->lock = SDL_CreateMutex();
if (retval->lock == NULL) { if (!retval->lock) {
SDL_free(retval->queue); SDL_free(retval->queue);
SDL_free(retval); SDL_free(retval);
return NULL; return NULL;
@ -632,9 +632,9 @@ int SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len)
SDL_Log("AUDIOSTREAM: wants to put %d bytes", len); SDL_Log("AUDIOSTREAM: wants to put %d bytes", len);
#endif #endif
if (stream == NULL) { if (!stream) {
return SDL_InvalidParamError("stream"); return SDL_InvalidParamError("stream");
} else if (buf == NULL) { } else if (!buf) {
return SDL_InvalidParamError("buf"); return SDL_InvalidParamError("buf");
} else if (len < 0) { } else if (len < 0) {
return SDL_InvalidParamError("len"); return SDL_InvalidParamError("len");
@ -669,7 +669,7 @@ int SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len)
size_t chunk_size = SDL_GetAudioQueueChunkSize(stream->queue); size_t chunk_size = SDL_GetAudioQueueChunkSize(stream->queue);
track = SDL_CreateChunkedAudioTrack(&src_spec, buf, len, chunk_size); track = SDL_CreateChunkedAudioTrack(&src_spec, buf, len, chunk_size);
if (track == NULL) { if (!track) {
return -1; return -1;
} }
@ -680,7 +680,7 @@ int SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len)
int retval = 0; int retval = 0;
if (track != NULL) { if (track) {
SDL_AddTrackToAudioQueue(stream->queue, track); SDL_AddTrackToAudioQueue(stream->queue, track);
} else { } else {
retval = SDL_WriteToAudioQueue(stream->queue, &stream->src_spec, buf, len); retval = SDL_WriteToAudioQueue(stream->queue, &stream->src_spec, buf, len);
@ -701,7 +701,7 @@ int SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len)
int SDL_FlushAudioStream(SDL_AudioStream *stream) int SDL_FlushAudioStream(SDL_AudioStream *stream)
{ {
if (stream == NULL) { if (!stream) {
return SDL_InvalidParamError("stream"); return SDL_InvalidParamError("stream");
} }
@ -721,7 +721,7 @@ static Uint8 *EnsureAudioStreamWorkBufferSize(SDL_AudioStream *stream, size_t ne
} }
Uint8 *ptr = (Uint8 *) SDL_aligned_alloc(SDL_SIMDGetAlignment(), newlen); Uint8 *ptr = (Uint8 *) SDL_aligned_alloc(SDL_SIMDGetAlignment(), newlen);
if (ptr == NULL) { if (!ptr) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; // previous work buffer is still valid! return NULL; // previous work buffer is still valid!
} }
@ -741,7 +741,7 @@ static void UpdateAudioStreamHistoryBuffer(SDL_AudioStream* stream,
Uint8 *history_buffer = stream->history_buffer; Uint8 *history_buffer = stream->history_buffer;
int history_bytes = history_buffer_frames * SDL_AUDIO_FRAMESIZE(stream->input_spec); int history_bytes = history_buffer_frames * SDL_AUDIO_FRAMESIZE(stream->input_spec);
if (left_padding != NULL) { if (left_padding) {
// Fill in the left padding using the history buffer // Fill in the left padding using the history buffer
SDL_assert(padding_bytes <= history_bytes); SDL_assert(padding_bytes <= history_bytes);
SDL_memcpy(left_padding, history_buffer + history_bytes - padding_bytes, padding_bytes); SDL_memcpy(left_padding, history_buffer + history_bytes - padding_bytes, padding_bytes);
@ -835,7 +835,7 @@ static Sint64 GetAudioStreamHead(SDL_AudioStream* stream, SDL_AudioSpec* out_spe
{ {
void* iter = SDL_BeginAudioQueueIter(stream->queue); void* iter = SDL_BeginAudioQueueIter(stream->queue);
if (iter == NULL) { if (!iter) {
SDL_zerop(out_spec); SDL_zerop(out_spec);
*out_flushed = SDL_FALSE; *out_flushed = SDL_FALSE;
return 0; return 0;
@ -1025,9 +1025,9 @@ int SDL_GetAudioStreamData(SDL_AudioStream *stream, void *voidbuf, int len)
SDL_Log("AUDIOSTREAM: want to get %d converted bytes", len); SDL_Log("AUDIOSTREAM: want to get %d converted bytes", len);
#endif #endif
if (stream == NULL) { if (!stream) {
return SDL_InvalidParamError("stream"); return SDL_InvalidParamError("stream");
} else if (buf == NULL) { } else if (!buf) {
return SDL_InvalidParamError("buf"); return SDL_InvalidParamError("buf");
} else if (len < 0) { } else if (len < 0) {
return SDL_InvalidParamError("len"); return SDL_InvalidParamError("len");
@ -1160,7 +1160,7 @@ int SDL_GetAudioStreamQueued(SDL_AudioStream *stream)
int SDL_ClearAudioStream(SDL_AudioStream *stream) int SDL_ClearAudioStream(SDL_AudioStream *stream)
{ {
if (stream == NULL) { if (!stream) {
return SDL_InvalidParamError("stream"); return SDL_InvalidParamError("stream");
} }
@ -1177,7 +1177,7 @@ int SDL_ClearAudioStream(SDL_AudioStream *stream)
void SDL_DestroyAudioStream(SDL_AudioStream *stream) void SDL_DestroyAudioStream(SDL_AudioStream *stream)
{ {
if (stream == NULL) { if (!stream) {
return; return;
} }
@ -1214,13 +1214,13 @@ int SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data
*dst_len = 0; *dst_len = 0;
} }
if (src_data == NULL) { if (!src_data) {
return SDL_InvalidParamError("src_data"); return SDL_InvalidParamError("src_data");
} else if (src_len < 0) { } else if (src_len < 0) {
return SDL_InvalidParamError("src_len"); return SDL_InvalidParamError("src_len");
} else if (dst_data == NULL) { } else if (!dst_data) {
return SDL_InvalidParamError("dst_data"); return SDL_InvalidParamError("dst_data");
} else if (dst_len == NULL) { } else if (!dst_len) {
return SDL_InvalidParamError("dst_len"); return SDL_InvalidParamError("dst_len");
} }
@ -1229,7 +1229,7 @@ int SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data
int dstlen = 0; int dstlen = 0;
SDL_AudioStream *stream = SDL_CreateAudioStream(src_spec, dst_spec); SDL_AudioStream *stream = SDL_CreateAudioStream(src_spec, dst_spec);
if (stream != NULL) { if (stream) {
if ((SDL_PutAudioStreamData(stream, src_data, src_len) == 0) && (SDL_FlushAudioStream(stream) == 0)) { if ((SDL_PutAudioStreamData(stream, src_data, src_len) == 0) && (SDL_FlushAudioStream(stream) == 0)) {
dstlen = SDL_GetAudioStreamAvailable(stream); dstlen = SDL_GetAudioStreamAvailable(stream);
if (dstlen >= 0) { if (dstlen >= 0) {

View File

@ -80,16 +80,16 @@ static void SDL_EnumUnixAudioDevices_Internal(const SDL_bool iscapture, const SD
const char *audiodev; const char *audiodev;
char audiopath[1024]; char audiopath[1024];
if (test == NULL) { if (!test) {
test = test_stub; test = test_stub;
} }
// Figure out what our audio device is // Figure out what our audio device is
audiodev = SDL_getenv("SDL_PATH_DSP"); audiodev = SDL_getenv("SDL_PATH_DSP");
if (audiodev == NULL) { if (!audiodev) {
audiodev = SDL_getenv("AUDIODEV"); audiodev = SDL_getenv("AUDIODEV");
} }
if (audiodev == NULL) { if (!audiodev) {
if (classic) { if (classic) {
audiodev = SDL_PATH_DEV_AUDIO; audiodev = SDL_PATH_DEV_AUDIO;
} else { } else {

View File

@ -92,7 +92,7 @@ static SDL_AudioChunk *CreateAudioChunk(size_t chunk_size)
{ {
SDL_AudioChunk *chunk = (SDL_AudioChunk *)SDL_malloc(sizeof(*chunk) + chunk_size); SDL_AudioChunk *chunk = (SDL_AudioChunk *)SDL_malloc(sizeof(*chunk) + chunk_size);
if (chunk == NULL) { if (!chunk) {
return NULL; return NULL;
} }
@ -146,14 +146,14 @@ static int WriteToChunkedAudioTrack(void *ctx, const Uint8 *data, size_t len)
SDL_AudioChunk *chunk = track->tail; SDL_AudioChunk *chunk = track->tail;
// Handle the first chunk // Handle the first chunk
if (chunk == NULL) { if (!chunk) {
chunk = CreateAudioTrackChunk(track); chunk = CreateAudioTrackChunk(track);
if (chunk == NULL) { if (!chunk) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_assert((track->head == NULL) && (track->tail == NULL) && (track->queued_bytes == 0)); SDL_assert((!track->head) && (!track->tail) && (track->queued_bytes == 0));
track->head = chunk; track->head = chunk;
track->tail = chunk; track->tail = chunk;
} }
@ -180,7 +180,7 @@ static int WriteToChunkedAudioTrack(void *ctx, const Uint8 *data, size_t len)
} }
// Roll back the changes if we couldn't write all the data // Roll back the changes if we couldn't write all the data
if (chunk == NULL) { if (!chunk) {
chunk = track->tail; chunk = track->tail;
SDL_AudioChunk *next = chunk->next; SDL_AudioChunk *next = chunk->next;
@ -255,7 +255,7 @@ static SDL_AudioTrack *CreateChunkedAudioTrack(const SDL_AudioSpec *spec, size_t
{ {
SDL_ChunkedAudioTrack *track = (SDL_ChunkedAudioTrack *)SDL_calloc(1, sizeof(*track)); SDL_ChunkedAudioTrack *track = (SDL_ChunkedAudioTrack *)SDL_calloc(1, sizeof(*track));
if (track == NULL) { if (!track) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
@ -275,7 +275,7 @@ SDL_AudioQueue *SDL_CreateAudioQueue(size_t chunk_size)
{ {
SDL_AudioQueue *queue = (SDL_AudioQueue *)SDL_calloc(1, sizeof(*queue)); SDL_AudioQueue *queue = (SDL_AudioQueue *)SDL_calloc(1, sizeof(*queue));
if (queue == NULL) { if (!queue) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
@ -338,7 +338,7 @@ void SDL_PopAudioQueueHead(SDL_AudioQueue *queue)
queue->head = track; queue->head = track;
if (track == NULL) { if (!track) {
queue->tail = NULL; queue->tail = NULL;
} }
} }
@ -352,7 +352,7 @@ SDL_AudioTrack *SDL_CreateChunkedAudioTrack(const SDL_AudioSpec *spec, const Uin
{ {
SDL_AudioTrack *track = CreateChunkedAudioTrack(spec, chunk_size); SDL_AudioTrack *track = CreateChunkedAudioTrack(spec, chunk_size);
if (track == NULL) { if (!track) {
return NULL; return NULL;
} }
@ -390,14 +390,14 @@ int SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, cons
SDL_AudioTrack *track = queue->tail; SDL_AudioTrack *track = queue->tail;
if ((track != NULL) && !AUDIO_SPECS_EQUAL(track->spec, *spec)) { if ((track) && !AUDIO_SPECS_EQUAL(track->spec, *spec)) {
SDL_FlushAudioTrack(track); SDL_FlushAudioTrack(track);
} }
if ((track == NULL) || (track->write == NULL)) { if ((!track) || (!track->write)) {
SDL_AudioTrack *new_track = CreateChunkedAudioTrack(spec, queue->chunk_size); SDL_AudioTrack *new_track = CreateChunkedAudioTrack(spec, queue->chunk_size);
if (new_track == NULL) { if (!new_track) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -423,7 +423,7 @@ void *SDL_BeginAudioQueueIter(SDL_AudioQueue *queue)
size_t SDL_NextAudioQueueIter(SDL_AudioQueue *queue, void **inout_iter, SDL_AudioSpec *out_spec, SDL_bool *out_flushed) size_t SDL_NextAudioQueueIter(SDL_AudioQueue *queue, void **inout_iter, SDL_AudioSpec *out_spec, SDL_bool *out_flushed)
{ {
SDL_AudioTrack *iter = *inout_iter; SDL_AudioTrack *iter = *inout_iter;
SDL_assert(iter != NULL); SDL_assert(iter);
SDL_copyp(out_spec, &iter->spec); SDL_copyp(out_spec, &iter->spec);
@ -462,7 +462,7 @@ int SDL_ReadFromAudioQueue(SDL_AudioQueue *queue, Uint8 *data, size_t len)
SDL_AudioTrack *track = queue->head; SDL_AudioTrack *track = queue->head;
for (;;) { for (;;) {
if (track == NULL) { if (!track) {
return SDL_SetError("Reading past end of queue"); return SDL_SetError("Reading past end of queue");
} }
@ -478,7 +478,7 @@ int SDL_ReadFromAudioQueue(SDL_AudioQueue *queue, Uint8 *data, size_t len)
SDL_AudioTrack *next = track->next; SDL_AudioTrack *next = track->next;
if (next == NULL) { if (!next) {
return SDL_SetError("Reading past end of incomplete track"); return SDL_SetError("Reading past end of incomplete track");
} }
@ -495,7 +495,7 @@ int SDL_PeekIntoAudioQueue(SDL_AudioQueue *queue, Uint8 *data, size_t len)
SDL_AudioTrack *track = queue->head; SDL_AudioTrack *track = queue->head;
for (;;) { for (;;) {
if (track == NULL) { if (!track) {
return SDL_SetError("Peeking past end of queue"); return SDL_SetError("Peeking past end of queue");
} }

View File

@ -262,7 +262,7 @@ static void WaveDebugDumpFormat(WaveFile *file, Uint32 rifflen, Uint32 fmtlen, U
int res; int res;
dumpstr = SDL_malloc(bufsize); dumpstr = SDL_malloc(bufsize);
if (dumpstr == NULL) { if (!dumpstr) {
return; return;
} }
dumpstr[0] = 0; dumpstr[0] = 0;
@ -439,7 +439,7 @@ static int MS_ADPCM_Init(WaveFile *file, size_t datalength)
coeffdata = (MS_ADPCM_CoeffData *)SDL_malloc(sizeof(MS_ADPCM_CoeffData) + coeffcount * 4); coeffdata = (MS_ADPCM_CoeffData *)SDL_malloc(sizeof(MS_ADPCM_CoeffData) + coeffcount * 4);
file->decoderdata = coeffdata; /* Freed in cleanup. */ file->decoderdata = coeffdata; /* Freed in cleanup. */
if (coeffdata == NULL) { if (!coeffdata) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
coeffdata->coeff = &coeffdata->aligndummy; coeffdata->coeff = &coeffdata->aligndummy;
@ -682,7 +682,7 @@ static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
state.output.pos = 0; state.output.pos = 0;
state.output.size = outputsize / sizeof(Sint16); state.output.size = outputsize / sizeof(Sint16);
state.output.data = (Sint16 *)SDL_calloc(1, outputsize); state.output.data = (Sint16 *)SDL_calloc(1, outputsize);
if (state.output.data == NULL) { if (!state.output.data) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -1073,12 +1073,12 @@ static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len
state.output.pos = 0; state.output.pos = 0;
state.output.size = outputsize / sizeof(Sint16); state.output.size = outputsize / sizeof(Sint16);
state.output.data = (Sint16 *)SDL_malloc(outputsize); state.output.data = (Sint16 *)SDL_malloc(outputsize);
if (state.output.data == NULL) { if (!state.output.data) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
cstate = (Sint8 *)SDL_calloc(state.channels, sizeof(Sint8)); cstate = (Sint8 *)SDL_calloc(state.channels, sizeof(Sint8));
if (cstate == NULL) { if (!cstate) {
SDL_free(state.output.data); SDL_free(state.output.data);
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -1233,7 +1233,7 @@ static int LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
/* 1 to avoid allocating zero bytes, to keep static analysis happy. */ /* 1 to avoid allocating zero bytes, to keep static analysis happy. */
src = (Uint8 *)SDL_realloc(chunk->data, expanded_len ? expanded_len : 1); src = (Uint8 *)SDL_realloc(chunk->data, expanded_len ? expanded_len : 1);
if (src == NULL) { if (!src) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
chunk->data = NULL; chunk->data = NULL;
@ -1364,7 +1364,7 @@ static int PCM_ConvertSint24ToSint32(WaveFile *file, Uint8 **audio_buf, Uint32 *
/* 1 to avoid allocating zero bytes, to keep static analysis happy. */ /* 1 to avoid allocating zero bytes, to keep static analysis happy. */
ptr = (Uint8 *)SDL_realloc(chunk->data, expanded_len ? expanded_len : 1); ptr = (Uint8 *)SDL_realloc(chunk->data, expanded_len ? expanded_len : 1);
if (ptr == NULL) { if (!ptr) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -1440,7 +1440,7 @@ static WaveRiffSizeHint WaveGetRiffSizeHint(void)
{ {
const char *hint = SDL_GetHint(SDL_HINT_WAVE_RIFF_CHUNK_SIZE); const char *hint = SDL_GetHint(SDL_HINT_WAVE_RIFF_CHUNK_SIZE);
if (hint != NULL) { if (hint) {
if (SDL_strcmp(hint, "force") == 0) { if (SDL_strcmp(hint, "force") == 0) {
return RiffSizeForce; return RiffSizeForce;
} else if (SDL_strcmp(hint, "ignore") == 0) { } else if (SDL_strcmp(hint, "ignore") == 0) {
@ -1459,7 +1459,7 @@ static WaveTruncationHint WaveGetTruncationHint(void)
{ {
const char *hint = SDL_GetHint(SDL_HINT_WAVE_TRUNCATION); const char *hint = SDL_GetHint(SDL_HINT_WAVE_TRUNCATION);
if (hint != NULL) { if (hint) {
if (SDL_strcmp(hint, "verystrict") == 0) { if (SDL_strcmp(hint, "verystrict") == 0) {
return TruncVeryStrict; return TruncVeryStrict;
} else if (SDL_strcmp(hint, "strict") == 0) { } else if (SDL_strcmp(hint, "strict") == 0) {
@ -1478,7 +1478,7 @@ static WaveFactChunkHint WaveGetFactChunkHint(void)
{ {
const char *hint = SDL_GetHint(SDL_HINT_WAVE_FACT_CHUNK); const char *hint = SDL_GetHint(SDL_HINT_WAVE_FACT_CHUNK);
if (hint != NULL) { if (hint) {
if (SDL_strcmp(hint, "truncate") == 0) { if (SDL_strcmp(hint, "truncate") == 0) {
return FactTruncate; return FactTruncate;
} else if (SDL_strcmp(hint, "strict") == 0) { } else if (SDL_strcmp(hint, "strict") == 0) {
@ -1495,7 +1495,7 @@ static WaveFactChunkHint WaveGetFactChunkHint(void)
static void WaveFreeChunkData(WaveChunk *chunk) static void WaveFreeChunkData(WaveChunk *chunk)
{ {
if (chunk->data != NULL) { if (chunk->data) {
SDL_free(chunk->data); SDL_free(chunk->data);
chunk->data = NULL; chunk->data = NULL;
} }
@ -1544,7 +1544,7 @@ static int WaveReadPartialChunkData(SDL_RWops *src, WaveChunk *chunk, size_t len
if (length > 0) { if (length > 0) {
chunk->data = (Uint8 *)SDL_malloc(length); chunk->data = (Uint8 *)SDL_malloc(length);
if (chunk->data == NULL) { if (!chunk->data) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -1610,7 +1610,7 @@ static int WaveReadFormat(WaveFile *file)
return SDL_SetError("Data of WAVE fmt chunk too big"); return SDL_SetError("Data of WAVE fmt chunk too big");
} }
fmtsrc = SDL_RWFromConstMem(chunk->data, (int)chunk->size); fmtsrc = SDL_RWFromConstMem(chunk->data, (int)chunk->size);
if (fmtsrc == NULL) { if (!fmtsrc) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -1788,7 +1788,7 @@ static int WaveLoad(SDL_RWops *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 *
SDL_zero(datachunk); SDL_zero(datachunk);
envchunkcountlimit = SDL_getenv("SDL_WAVE_CHUNK_LIMIT"); envchunkcountlimit = SDL_getenv("SDL_WAVE_CHUNK_LIMIT");
if (envchunkcountlimit != NULL) { if (envchunkcountlimit) {
unsigned int count; unsigned int count;
if (SDL_sscanf(envchunkcountlimit, "%u", &count) == 1) { if (SDL_sscanf(envchunkcountlimit, "%u", &count) == 1) {
chunkcountlimit = count <= SDL_MAX_UINT32 ? count : SDL_MAX_UINT32; chunkcountlimit = count <= SDL_MAX_UINT32 ? count : SDL_MAX_UINT32;
@ -2081,15 +2081,15 @@ int SDL_LoadWAV_RW(SDL_RWops *src, SDL_bool freesrc, SDL_AudioSpec *spec, Uint8
WaveFile file; WaveFile file;
/* Make sure we are passed a valid data source */ /* Make sure we are passed a valid data source */
if (src == NULL) { if (!src) {
goto done; /* Error may come from RWops. */ goto done; /* Error may come from RWops. */
} else if (spec == NULL) { } else if (!spec) {
SDL_InvalidParamError("spec"); SDL_InvalidParamError("spec");
goto done; goto done;
} else if (audio_buf == NULL) { } else if (!audio_buf) {
SDL_InvalidParamError("audio_buf"); SDL_InvalidParamError("audio_buf");
goto done; goto done;
} else if (audio_len == NULL) { } else if (!audio_len) {
SDL_InvalidParamError("audio_len"); SDL_InvalidParamError("audio_len");
goto done; goto done;
} }

View File

@ -282,7 +282,7 @@ static int BuildAAudioStream(SDL_AudioDevice *device)
if (res != AAUDIO_OK) { if (res != AAUDIO_OK) {
LOGI("SDL Failed AAudio_createStreamBuilder %d", res); LOGI("SDL Failed AAudio_createStreamBuilder %d", res);
return SDL_SetError("SDL Failed AAudio_createStreamBuilder %d", res); return SDL_SetError("SDL Failed AAudio_createStreamBuilder %d", res);
} else if (builder == NULL) { } else if (!builder) {
LOGI("SDL Failed AAudio_createStreamBuilder - builder NULL"); LOGI("SDL Failed AAudio_createStreamBuilder - builder NULL");
return SDL_SetError("SDL Failed AAudio_createStreamBuilder - builder NULL"); return SDL_SetError("SDL Failed AAudio_createStreamBuilder - builder NULL");
} }
@ -354,7 +354,7 @@ static int BuildAAudioStream(SDL_AudioDevice *device)
hidden->num_buffers = 2; hidden->num_buffers = 2;
hidden->mixbuf_bytes = (hidden->num_buffers * device->buffer_size); hidden->mixbuf_bytes = (hidden->num_buffers * device->buffer_size);
hidden->mixbuf = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), hidden->mixbuf_bytes); hidden->mixbuf = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), hidden->mixbuf_bytes);
if (hidden->mixbuf == NULL) { if (!hidden->mixbuf) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
hidden->processed_bytes = 0; hidden->processed_bytes = 0;
@ -384,7 +384,7 @@ static int BuildAAudioStream(SDL_AudioDevice *device)
static int AAUDIO_OpenDevice(SDL_AudioDevice *device) static int AAUDIO_OpenDevice(SDL_AudioDevice *device)
{ {
#if ALLOW_MULTIPLE_ANDROID_AUDIO_DEVICES #if ALLOW_MULTIPLE_ANDROID_AUDIO_DEVICES
SDL_assert(device->handle != NULL); // AAUDIO_UNSPECIFIED is zero, so legit devices should all be non-zero. SDL_assert(device->handle); // AAUDIO_UNSPECIFIED is zero, so legit devices should all be non-zero.
#endif #endif
LOGI(__func__); LOGI(__func__);
@ -397,7 +397,7 @@ static int AAUDIO_OpenDevice(SDL_AudioDevice *device)
} }
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -407,7 +407,7 @@ static int AAUDIO_OpenDevice(SDL_AudioDevice *device)
static SDL_bool PauseOneDevice(SDL_AudioDevice *device, void *userdata) static SDL_bool PauseOneDevice(SDL_AudioDevice *device, void *userdata)
{ {
struct SDL_PrivateAudioData *hidden = (struct SDL_PrivateAudioData *)device->hidden; struct SDL_PrivateAudioData *hidden = (struct SDL_PrivateAudioData *)device->hidden;
if (hidden != NULL) { if (hidden) {
if (hidden->stream) { if (hidden->stream) {
aaudio_result_t res; aaudio_result_t res;
@ -433,7 +433,7 @@ static SDL_bool PauseOneDevice(SDL_AudioDevice *device, void *userdata)
// Pause (block) all non already paused audio devices by taking their mixer lock // Pause (block) all non already paused audio devices by taking their mixer lock
void AAUDIO_PauseDevices(void) void AAUDIO_PauseDevices(void)
{ {
if (ctx.handle != NULL) { // AAUDIO driver is used? if (ctx.handle) { // AAUDIO driver is used?
(void) SDL_FindPhysicalAudioDeviceByCallback(PauseOneDevice, NULL); (void) SDL_FindPhysicalAudioDeviceByCallback(PauseOneDevice, NULL);
} }
} }
@ -442,7 +442,7 @@ void AAUDIO_PauseDevices(void)
static SDL_bool ResumeOneDevice(SDL_AudioDevice *device, void *userdata) static SDL_bool ResumeOneDevice(SDL_AudioDevice *device, void *userdata)
{ {
struct SDL_PrivateAudioData *hidden = device->hidden; struct SDL_PrivateAudioData *hidden = device->hidden;
if (hidden != NULL) { if (hidden) {
if (hidden->resume) { if (hidden->resume) {
hidden->resume = SDL_FALSE; hidden->resume = SDL_FALSE;
SDL_UnlockMutex(device->lock); SDL_UnlockMutex(device->lock);
@ -461,7 +461,7 @@ static SDL_bool ResumeOneDevice(SDL_AudioDevice *device, void *userdata)
void AAUDIO_ResumeDevices(void) void AAUDIO_ResumeDevices(void)
{ {
if (ctx.handle != NULL) { // AAUDIO driver is used? if (ctx.handle) { // AAUDIO driver is used?
(void) SDL_FindPhysicalAudioDeviceByCallback(ResumeOneDevice, NULL); (void) SDL_FindPhysicalAudioDeviceByCallback(ResumeOneDevice, NULL);
} }
} }
@ -495,7 +495,7 @@ static SDL_bool AAUDIO_Init(SDL_AudioDriverImpl *impl)
SDL_zero(ctx); SDL_zero(ctx);
ctx.handle = SDL_LoadObject(LIB_AAUDIO_SO); ctx.handle = SDL_LoadObject(LIB_AAUDIO_SO);
if (ctx.handle == NULL) { if (!ctx.handle) {
LOGI("SDL couldn't find " LIB_AAUDIO_SO); LOGI("SDL couldn't find " LIB_AAUDIO_SO);
return SDL_FALSE; return SDL_FALSE;
} }

View File

@ -96,7 +96,7 @@ static void *alsa_handle = NULL;
static int load_alsa_sym(const char *fn, void **addr) static int load_alsa_sym(const char *fn, void **addr)
{ {
*addr = SDL_LoadFunction(alsa_handle, fn); *addr = SDL_LoadFunction(alsa_handle, fn);
if (*addr == NULL) { if (!*addr) {
// Don't call SDL_SetError(): SDL_LoadFunction already did. // Don't call SDL_SetError(): SDL_LoadFunction already did.
return 0; return 0;
} }
@ -165,7 +165,7 @@ static int load_alsa_syms(void)
static void UnloadALSALibrary(void) static void UnloadALSALibrary(void)
{ {
if (alsa_handle != NULL) { if (alsa_handle) {
SDL_UnloadObject(alsa_handle); SDL_UnloadObject(alsa_handle);
alsa_handle = NULL; alsa_handle = NULL;
} }
@ -174,9 +174,9 @@ static void UnloadALSALibrary(void)
static int LoadALSALibrary(void) static int LoadALSALibrary(void)
{ {
int retval = 0; int retval = 0;
if (alsa_handle == NULL) { if (!alsa_handle) {
alsa_handle = SDL_LoadObject(alsa_library); alsa_handle = SDL_LoadObject(alsa_library);
if (alsa_handle == NULL) { if (!alsa_handle) {
retval = -1; retval = -1;
// Don't call SDL_SetError(): SDL_LoadObject already did. // Don't call SDL_SetError(): SDL_LoadObject already did.
} else { } else {
@ -224,12 +224,12 @@ static const ALSA_Device default_capture_handle = {
static const char *get_audio_device(void *handle, const int channels) static const char *get_audio_device(void *handle, const int channels)
{ {
SDL_assert(handle != NULL); // SDL2 used NULL to mean "default" but that's not true in SDL3. SDL_assert(handle); // SDL2 used NULL to mean "default" but that's not true in SDL3.
ALSA_Device *dev = (ALSA_Device *)handle; ALSA_Device *dev = (ALSA_Device *)handle;
if (SDL_strcmp(dev->name, "default") == 0) { if (SDL_strcmp(dev->name, "default") == 0) {
const char *device = SDL_getenv("AUDIODEV"); // Is there a standard variable name? const char *device = SDL_getenv("AUDIODEV"); // Is there a standard variable name?
if (device != NULL) { if (device) {
return device; return device;
} else if (channels == 6) { } else if (channels == 6) {
return "plug:surround51"; return "plug:surround51";
@ -536,7 +536,7 @@ static int ALSA_OpenDevice(SDL_AudioDevice *device)
// Initialize all variables that we clean on shutdown // Initialize all variables that we clean on shutdown
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -682,7 +682,7 @@ static int ALSA_OpenDevice(SDL_AudioDevice *device)
// Allocate mixing buffer // Allocate mixing buffer
if (!iscapture) { if (!iscapture) {
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
if (device->hidden->mixbuf == NULL) { if (!device->hidden->mixbuf) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);
@ -705,7 +705,7 @@ static void add_device(const SDL_bool iscapture, const char *name, void *hint, A
char *desc; char *desc;
char *ptr; char *ptr;
if (dev == NULL) { if (!dev) {
return; return;
} }
@ -715,7 +715,7 @@ static void add_device(const SDL_bool iscapture, const char *name, void *hint, A
// Make sure not to free the storage associated with desc in this case // Make sure not to free the storage associated with desc in this case
if (hint) { if (hint) {
desc = ALSA_snd_device_name_get_hint(hint, "DESC"); desc = ALSA_snd_device_name_get_hint(hint, "DESC");
if (desc == NULL) { if (!desc) {
SDL_free(dev); SDL_free(dev);
return; return;
} }
@ -723,13 +723,13 @@ static void add_device(const SDL_bool iscapture, const char *name, void *hint, A
desc = (char *)name; desc = (char *)name;
} }
SDL_assert(name != NULL); SDL_assert(name);
// some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output". // some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output".
// just chop the extra lines off, this seems to get a reasonable device // just chop the extra lines off, this seems to get a reasonable device
// name without extra details. // name without extra details.
ptr = SDL_strchr(desc, '\n'); ptr = SDL_strchr(desc, '\n');
if (ptr != NULL) { if (ptr) {
*ptr = '\0'; *ptr = '\0';
} }
@ -784,7 +784,7 @@ static void ALSA_HotplugIteration(SDL_bool *has_default_output, SDL_bool *has_de
// if we can find a preferred prefix for the system. // if we can find a preferred prefix for the system.
for (int i = 0; hints[i]; i++) { for (int i = 0; hints[i]; i++) {
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME"); char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
if (name == NULL) { if (!name) {
continue; continue;
} }
@ -813,16 +813,16 @@ static void ALSA_HotplugIteration(SDL_bool *has_default_output, SDL_bool *has_de
if (match || (has_default >= 0)) { // did we find a device name prefix we like at all...? if (match || (has_default >= 0)) { // did we find a device name prefix we like at all...?
for (int i = 0; hints[i]; i++) { for (int i = 0; hints[i]; i++) {
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME"); char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
if (name == NULL) { if (!name) {
continue; continue;
} }
// only want physical hardware interfaces // only want physical hardware interfaces
const SDL_bool is_default = (has_default == i); const SDL_bool is_default = (has_default == i);
if (is_default || (match != NULL && SDL_strncmp(name, match, match_len) == 0)) { if (is_default || (match && SDL_strncmp(name, match, match_len) == 0)) {
char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID"); char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID");
const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0); const SDL_bool isoutput = (!ioid) || (SDL_strcmp(ioid, "Output") == 0);
const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0); const SDL_bool isinput = (!ioid) || (SDL_strcmp(ioid, "Input") == 0);
SDL_bool have_output = SDL_FALSE; SDL_bool have_output = SDL_FALSE;
SDL_bool have_input = SDL_FALSE; SDL_bool have_input = SDL_FALSE;
@ -942,7 +942,7 @@ static void ALSA_DeinitializeStart(void)
ALSA_Device *next; ALSA_Device *next;
#if SDL_ALSA_HOTPLUG_THREAD #if SDL_ALSA_HOTPLUG_THREAD
if (ALSA_hotplug_thread != NULL) { if (ALSA_hotplug_thread) {
SDL_AtomicSet(&ALSA_hotplug_shutdown, 1); SDL_AtomicSet(&ALSA_hotplug_shutdown, 1);
SDL_WaitThread(ALSA_hotplug_thread, NULL); SDL_WaitThread(ALSA_hotplug_thread, NULL);
ALSA_hotplug_thread = NULL; ALSA_hotplug_thread = NULL;

View File

@ -42,7 +42,7 @@ static SDL_AudioDevice *captureDevice = NULL;
static int ANDROIDAUDIO_OpenDevice(SDL_AudioDevice *device) static int ANDROIDAUDIO_OpenDevice(SDL_AudioDevice *device)
{ {
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -131,13 +131,13 @@ void ANDROIDAUDIO_PauseDevices(void)
{ {
// TODO: Handle multiple devices? // TODO: Handle multiple devices?
struct SDL_PrivateAudioData *hidden; struct SDL_PrivateAudioData *hidden;
if (audioDevice != NULL && audioDevice->hidden != NULL) { if (audioDevice && audioDevice->hidden) {
hidden = (struct SDL_PrivateAudioData *)audioDevice->hidden; hidden = (struct SDL_PrivateAudioData *)audioDevice->hidden;
SDL_LockMutex(audioDevice->lock); SDL_LockMutex(audioDevice->lock);
hidden->resume = SDL_TRUE; hidden->resume = SDL_TRUE;
} }
if (captureDevice != NULL && captureDevice->hidden != NULL) { if (captureDevice && captureDevice->hidden) {
hidden = (struct SDL_PrivateAudioData *)captureDevice->hidden; hidden = (struct SDL_PrivateAudioData *)captureDevice->hidden;
SDL_LockMutex(captureDevice->lock); SDL_LockMutex(captureDevice->lock);
hidden->resume = SDL_TRUE; hidden->resume = SDL_TRUE;
@ -149,7 +149,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
{ {
// TODO: Handle multiple devices? // TODO: Handle multiple devices?
struct SDL_PrivateAudioData *hidden; struct SDL_PrivateAudioData *hidden;
if (audioDevice != NULL && audioDevice->hidden != NULL) { if (audioDevice && audioDevice->hidden) {
hidden = (struct SDL_PrivateAudioData *)audioDevice->hidden; hidden = (struct SDL_PrivateAudioData *)audioDevice->hidden;
if (hidden->resume) { if (hidden->resume) {
hidden->resume = SDL_FALSE; hidden->resume = SDL_FALSE;
@ -157,7 +157,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
} }
} }
if (captureDevice != NULL && captureDevice->hidden != NULL) { if (captureDevice && captureDevice->hidden) {
hidden = (struct SDL_PrivateAudioData *)captureDevice->hidden; hidden = (struct SDL_PrivateAudioData *)captureDevice->hidden;
if (hidden->resume) { if (hidden->resume) {
hidden->resume = SDL_FALSE; hidden->resume = SDL_FALSE;

View File

@ -62,7 +62,7 @@ static void DSOUND_Unload(void)
pDirectSoundCaptureEnumerateW = NULL; pDirectSoundCaptureEnumerateW = NULL;
pGetDeviceID = NULL; pGetDeviceID = NULL;
if (DSoundDLL != NULL) { if (DSoundDLL) {
SDL_UnloadObject(DSoundDLL); SDL_UnloadObject(DSoundDLL);
DSoundDLL = NULL; DSoundDLL = NULL;
} }
@ -75,7 +75,7 @@ static int DSOUND_Load(void)
DSOUND_Unload(); DSOUND_Unload();
DSoundDLL = SDL_LoadObject("DSOUND.DLL"); DSoundDLL = SDL_LoadObject("DSOUND.DLL");
if (DSoundDLL == NULL) { if (!DSoundDLL) {
SDL_SetError("DirectSound: failed to load DSOUND.DLL"); SDL_SetError("DirectSound: failed to load DSOUND.DLL");
} else { } else {
// Now make sure we have DirectX 8 or better... // Now make sure we have DirectX 8 or better...
@ -176,7 +176,7 @@ static BOOL CALLBACK FindAllDevs(LPGUID guid, LPCWSTR desc, LPCWSTR module, LPVO
FindAllDevsData *data = (FindAllDevsData *) userdata; FindAllDevsData *data = (FindAllDevsData *) userdata;
if (guid != NULL) { // skip default device if (guid != NULL) { // skip default device
char *str = WIN_LookupAudioDeviceName(desc, guid); char *str = WIN_LookupAudioDeviceName(desc, guid);
if (str != NULL) { if (str) {
LPGUID cpyguid = (LPGUID)SDL_malloc(sizeof(GUID)); LPGUID cpyguid = (LPGUID)SDL_malloc(sizeof(GUID));
if (cpyguid) { if (cpyguid) {
SDL_copyp(cpyguid, guid); SDL_copyp(cpyguid, guid);
@ -358,7 +358,7 @@ static int DSOUND_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, int b
} }
SDL_assert(ptr1len == (DWORD)buflen); SDL_assert(ptr1len == (DWORD)buflen);
SDL_assert(ptr2 == NULL); SDL_assert(!ptr2);
SDL_assert(ptr2len == 0); SDL_assert(ptr2len == 0);
SDL_memcpy(buffer, ptr1, ptr1len); SDL_memcpy(buffer, ptr1, ptr1len);
@ -384,18 +384,18 @@ static void DSOUND_FlushCapture(SDL_AudioDevice *device)
static void DSOUND_CloseDevice(SDL_AudioDevice *device) static void DSOUND_CloseDevice(SDL_AudioDevice *device)
{ {
if (device->hidden) { if (device->hidden) {
if (device->hidden->mixbuf != NULL) { if (device->hidden->mixbuf) {
IDirectSoundBuffer_Stop(device->hidden->mixbuf); IDirectSoundBuffer_Stop(device->hidden->mixbuf);
IDirectSoundBuffer_Release(device->hidden->mixbuf); IDirectSoundBuffer_Release(device->hidden->mixbuf);
} }
if (device->hidden->sound != NULL) { if (device->hidden->sound) {
IDirectSound_Release(device->hidden->sound); IDirectSound_Release(device->hidden->sound);
} }
if (device->hidden->capturebuf != NULL) { if (device->hidden->capturebuf) {
IDirectSoundCaptureBuffer_Stop(device->hidden->capturebuf); IDirectSoundCaptureBuffer_Stop(device->hidden->capturebuf);
IDirectSoundCaptureBuffer_Release(device->hidden->capturebuf); IDirectSoundCaptureBuffer_Release(device->hidden->capturebuf);
} }
if (device->hidden->capture != NULL) { if (device->hidden->capture) {
IDirectSoundCapture_Release(device->hidden->capture); IDirectSoundCapture_Release(device->hidden->capture);
} }
SDL_free(device->hidden); SDL_free(device->hidden);
@ -491,7 +491,7 @@ static int DSOUND_OpenDevice(SDL_AudioDevice *device)
{ {
// Initialize all variables that we clean on shutdown // Initialize all variables that we clean on shutdown
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }

View File

@ -87,7 +87,7 @@ static void DISKAUDIO_FlushCapture(SDL_AudioDevice *device)
static void DISKAUDIO_CloseDevice(SDL_AudioDevice *device) static void DISKAUDIO_CloseDevice(SDL_AudioDevice *device)
{ {
if (device->hidden) { if (device->hidden) {
if (device->hidden->io != NULL) { if (device->hidden->io) {
SDL_RWclose(device->hidden->io); SDL_RWclose(device->hidden->io);
} }
SDL_free(device->hidden->mixbuf); SDL_free(device->hidden->mixbuf);
@ -99,7 +99,7 @@ static void DISKAUDIO_CloseDevice(SDL_AudioDevice *device)
static const char *get_filename(const SDL_bool iscapture) static const char *get_filename(const SDL_bool iscapture)
{ {
const char *devname = SDL_getenv(iscapture ? DISKENVR_INFILE : DISKENVR_OUTFILE); const char *devname = SDL_getenv(iscapture ? DISKENVR_INFILE : DISKENVR_OUTFILE);
if (devname == NULL) { if (!devname) {
devname = iscapture ? DISKDEFAULT_INFILE : DISKDEFAULT_OUTFILE; devname = iscapture ? DISKDEFAULT_INFILE : DISKDEFAULT_OUTFILE;
} }
return devname; return devname;
@ -112,11 +112,11 @@ static int DISKAUDIO_OpenDevice(SDL_AudioDevice *device)
const char *envr = SDL_getenv(DISKENVR_IODELAY); const char *envr = SDL_getenv(DISKENVR_IODELAY);
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
if (envr != NULL) { if (envr) {
device->hidden->io_delay = SDL_atoi(envr); device->hidden->io_delay = SDL_atoi(envr);
} else { } else {
device->hidden->io_delay = ((device->sample_frames * 1000) / device->spec.freq); device->hidden->io_delay = ((device->sample_frames * 1000) / device->spec.freq);
@ -124,14 +124,14 @@ static int DISKAUDIO_OpenDevice(SDL_AudioDevice *device)
// Open the "audio device" // Open the "audio device"
device->hidden->io = SDL_RWFromFile(fname, iscapture ? "rb" : "wb"); device->hidden->io = SDL_RWFromFile(fname, iscapture ? "rb" : "wb");
if (device->hidden->io == NULL) { if (!device->hidden->io) {
return -1; return -1;
} }
// Allocate mixing buffer // Allocate mixing buffer
if (!iscapture) { if (!iscapture) {
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
if (device->hidden->mixbuf == NULL) { if (!device->hidden->mixbuf) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);

View File

@ -70,7 +70,7 @@ static int DSP_OpenDevice(SDL_AudioDevice *device)
// Initialize all variables that we clean on shutdown // Initialize all variables that we clean on shutdown
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -191,7 +191,7 @@ static int DSP_OpenDevice(SDL_AudioDevice *device)
// Allocate mixing buffer // Allocate mixing buffer
if (!device->iscapture) { if (!device->iscapture) {
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
if (device->hidden->mixbuf == NULL) { if (!device->hidden->mixbuf) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);

View File

@ -177,7 +177,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device)
// Initialize all variables that we clean on shutdown // Initialize all variables that we clean on shutdown
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -188,7 +188,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device)
if (!device->iscapture) { if (!device->iscapture) {
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
if (device->hidden->mixbuf == NULL) { if (!device->hidden->mixbuf) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);

View File

@ -39,7 +39,7 @@ extern "C"
static Uint8 *HAIKUAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) static Uint8 *HAIKUAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
{ {
SDL_assert(device->hidden->current_buffer != NULL); SDL_assert(device->hidden->current_buffer);
SDL_assert(device->hidden->current_buffer_len > 0); SDL_assert(device->hidden->current_buffer_len > 0);
*buffer_size = device->hidden->current_buffer_len; *buffer_size = device->hidden->current_buffer_len;
return device->hidden->current_buffer; return device->hidden->current_buffer;
@ -48,7 +48,7 @@ static Uint8 *HAIKUAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
static int HAIKUAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) static int HAIKUAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
{ {
// We already wrote our output right into the BSoundPlayer's callback's stream. Just clean up our stuff. // We already wrote our output right into the BSoundPlayer's callback's stream. Just clean up our stuff.
SDL_assert(device->hidden->current_buffer != NULL); SDL_assert(device->hidden->current_buffer);
SDL_assert(device->hidden->current_buffer_len > 0); SDL_assert(device->hidden->current_buffer_len > 0);
device->hidden->current_buffer = NULL; device->hidden->current_buffer = NULL;
device->hidden->current_buffer_len = 0; device->hidden->current_buffer_len = 0;
@ -59,7 +59,7 @@ static int HAIKUAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, i
static void FillSound(void *data, void *stream, size_t len, const media_raw_audio_format & format) static void FillSound(void *data, void *stream, size_t len, const media_raw_audio_format & format)
{ {
SDL_AudioDevice *device = (SDL_AudioDevice *)data; SDL_AudioDevice *device = (SDL_AudioDevice *)data;
SDL_assert(device->hidden->current_buffer == NULL); SDL_assert(!device->hidden->current_buffer);
SDL_assert(device->hidden->current_buffer_len == 0); SDL_assert(device->hidden->current_buffer_len == 0);
device->hidden->current_buffer = (Uint8 *) stream; device->hidden->current_buffer = (Uint8 *) stream;
device->hidden->current_buffer_len = (int) len; device->hidden->current_buffer_len = (int) len;

View File

@ -57,7 +57,7 @@ static void *jack_handle = NULL;
static int load_jack_sym(const char *fn, void **addr) static int load_jack_sym(const char *fn, void **addr)
{ {
*addr = SDL_LoadFunction(jack_handle, fn); *addr = SDL_LoadFunction(jack_handle, fn);
if (*addr == NULL) { if (!*addr) {
// Don't call SDL_SetError(): SDL_LoadFunction already did. // Don't call SDL_SetError(): SDL_LoadFunction already did.
return 0; return 0;
} }
@ -72,7 +72,7 @@ static int load_jack_sym(const char *fn, void **addr)
static void UnloadJackLibrary(void) static void UnloadJackLibrary(void)
{ {
if (jack_handle != NULL) { if (jack_handle) {
SDL_UnloadObject(jack_handle); SDL_UnloadObject(jack_handle);
jack_handle = NULL; jack_handle = NULL;
} }
@ -81,9 +81,9 @@ static void UnloadJackLibrary(void)
static int LoadJackLibrary(void) static int LoadJackLibrary(void)
{ {
int retval = 0; int retval = 0;
if (jack_handle == NULL) { if (!jack_handle) {
jack_handle = SDL_LoadObject(jack_library); jack_handle = SDL_LoadObject(jack_library);
if (jack_handle == NULL) { if (!jack_handle) {
retval = -1; retval = -1;
// Don't call SDL_SetError(): SDL_LoadObject already did. // Don't call SDL_SetError(): SDL_LoadObject already did.
} else { } else {
@ -296,18 +296,18 @@ static int JACK_OpenDevice(SDL_AudioDevice *device)
// Initialize all variables that we clean on shutdown // Initialize all variables that we clean on shutdown
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
client = JACK_jack_client_open(GetJackAppName(), JackNoStartServer, &status, NULL); client = JACK_jack_client_open(GetJackAppName(), JackNoStartServer, &status, NULL);
device->hidden->client = client; device->hidden->client = client;
if (client == NULL) { if (!client) {
return SDL_SetError("Can't open JACK client"); return SDL_SetError("Can't open JACK client");
} }
devports = JACK_jack_get_ports(client, NULL, NULL, JackPortIsPhysical | sysportflags); devports = JACK_jack_get_ports(client, NULL, NULL, JackPortIsPhysical | sysportflags);
if (devports == NULL || !devports[0]) { if (!devports || !devports[0]) {
return SDL_SetError("No physical JACK ports available"); return SDL_SetError("No physical JACK ports available");
} }
@ -349,7 +349,7 @@ static int JACK_OpenDevice(SDL_AudioDevice *device)
// Build SDL's ports, which we will connect to the device ports. // Build SDL's ports, which we will connect to the device ports.
device->hidden->sdlports = (jack_port_t **)SDL_calloc(channels, sizeof(jack_port_t *)); device->hidden->sdlports = (jack_port_t **)SDL_calloc(channels, sizeof(jack_port_t *));
if (device->hidden->sdlports == NULL) { if (!device->hidden->sdlports) {
SDL_free(audio_ports); SDL_free(audio_ports);
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -414,7 +414,7 @@ static SDL_bool JACK_Init(SDL_AudioDriverImpl *impl)
// Make sure a JACK server is running and available. // Make sure a JACK server is running and available.
jack_status_t status; jack_status_t status;
jack_client_t *client = JACK_jack_client_open("SDL", JackNoStartServer, &status, NULL); jack_client_t *client = JACK_jack_client_open("SDL", JackNoStartServer, &status, NULL);
if (client == NULL) { if (!client) {
UnloadJackLibrary(); UnloadJackLibrary();
return SDL_FALSE; return SDL_FALSE;
} }

View File

@ -83,7 +83,7 @@ static int N3DSAUDIO_OpenDevice(SDL_AudioDevice *device)
float mix[12]; float mix[12];
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -134,14 +134,14 @@ static int N3DSAUDIO_OpenDevice(SDL_AudioDevice *device)
} }
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
if (device->hidden->mixbuf == NULL) { if (!device->hidden->mixbuf) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);
data_vaddr = (Uint8 *)linearAlloc(device->buffer_size * NUM_BUFFERS); data_vaddr = (Uint8 *)linearAlloc(device->buffer_size * NUM_BUFFERS);
if (data_vaddr == NULL) { if (!data_vaddr) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }

View File

@ -215,7 +215,7 @@ static int NETBSDAUDIO_OpenDevice(SDL_AudioDevice *device)
// Initialize all variables that we clean on shutdown // Initialize all variables that we clean on shutdown
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -293,7 +293,7 @@ static int NETBSDAUDIO_OpenDevice(SDL_AudioDevice *device)
// Allocate mixing buffer // Allocate mixing buffer
device->hidden->mixlen = device->buffer_size; device->hidden->mixlen = device->buffer_size;
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->hidden->mixlen); device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->hidden->mixlen);
if (device->hidden->mixbuf == NULL) { if (!device->hidden->mixbuf) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);

View File

@ -327,7 +327,7 @@ static int OPENSLES_CreatePCMRecorder(SDL_AudioDevice *device)
// Create the sound buffers // Create the sound buffers
audiodata->mixbuff = (Uint8 *)SDL_malloc(NUM_BUFFERS * device->buffer_size); audiodata->mixbuff = (Uint8 *)SDL_malloc(NUM_BUFFERS * device->buffer_size);
if (audiodata->mixbuff == NULL) { if (!audiodata->mixbuff) {
LOGE("mixbuffer allocate - out of memory"); LOGE("mixbuffer allocate - out of memory");
goto failed; goto failed;
} }
@ -574,7 +574,7 @@ static int OPENSLES_CreatePCMPlayer(SDL_AudioDevice *device)
// Create the sound buffers // Create the sound buffers
audiodata->mixbuff = (Uint8 *)SDL_malloc(NUM_BUFFERS * device->buffer_size); audiodata->mixbuff = (Uint8 *)SDL_malloc(NUM_BUFFERS * device->buffer_size);
if (audiodata->mixbuff == NULL) { if (!audiodata->mixbuff) {
LOGE("mixbuffer allocate - out of memory"); LOGE("mixbuffer allocate - out of memory");
goto failed; goto failed;
} }
@ -599,7 +599,7 @@ failed:
static int OPENSLES_OpenDevice(SDL_AudioDevice *device) static int OPENSLES_OpenDevice(SDL_AudioDevice *device)
{ {
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }

View File

@ -126,7 +126,7 @@ static void *pipewire_handle = NULL;
static int pipewire_dlsym(const char *fn, void **addr) static int pipewire_dlsym(const char *fn, void **addr)
{ {
*addr = SDL_LoadFunction(pipewire_handle, fn); *addr = SDL_LoadFunction(pipewire_handle, fn);
if (*addr == NULL) { if (!*addr) {
// Don't call SDL_SetError(): SDL_LoadFunction already did. // Don't call SDL_SetError(): SDL_LoadFunction already did.
return 0; return 0;
} }
@ -142,7 +142,7 @@ static int pipewire_dlsym(const char *fn, void **addr)
static int load_pipewire_library(void) static int load_pipewire_library(void)
{ {
pipewire_handle = SDL_LoadObject(pipewire_library); pipewire_handle = SDL_LoadObject(pipewire_library);
return pipewire_handle != NULL ? 0 : -1; return pipewire_handle ? 0 : -1;
} }
static void unload_pipewire_library(void) static void unload_pipewire_library(void)
@ -404,7 +404,7 @@ static void *node_object_new(Uint32 id, const char *type, Uint32 version, const
// Create the proxy object // Create the proxy object
proxy = pw_registry_bind(hotplug_registry, id, type, version, sizeof(struct node_object)); proxy = pw_registry_bind(hotplug_registry, id, type, version, sizeof(struct node_object));
if (proxy == NULL) { if (!proxy) {
SDL_SetError("Pipewire: Failed to create proxy object (%i)", errno); SDL_SetError("Pipewire: Failed to create proxy object (%i)", errno);
return NULL; return NULL;
} }
@ -623,16 +623,16 @@ static int metadata_property(void *object, Uint32 subject, const char *key, cons
{ {
struct node_object *node = object; struct node_object *node = object;
if (subject == PW_ID_CORE && key != NULL && value != NULL) { if (subject == PW_ID_CORE && key && value) {
if (!SDL_strcmp(key, "default.audio.sink")) { if (!SDL_strcmp(key, "default.audio.sink")) {
if (pipewire_default_sink_id != NULL) { if (pipewire_default_sink_id) {
SDL_free(pipewire_default_sink_id); SDL_free(pipewire_default_sink_id);
} }
pipewire_default_sink_id = get_name_from_json(value); pipewire_default_sink_id = get_name_from_json(value);
node->persist = SDL_TRUE; node->persist = SDL_TRUE;
change_default_device(pipewire_default_sink_id); change_default_device(pipewire_default_sink_id);
} else if (!SDL_strcmp(key, "default.audio.source")) { } else if (!SDL_strcmp(key, "default.audio.source")) {
if (pipewire_default_source_id != NULL) { if (pipewire_default_source_id) {
SDL_free(pipewire_default_source_id); SDL_free(pipewire_default_source_id);
} }
pipewire_default_source_id = get_name_from_json(value); pipewire_default_source_id = get_name_from_json(value);
@ -678,7 +678,7 @@ static void registry_event_global_callback(void *object, uint32_t id, uint32_t p
if (node_desc && node_path) { if (node_desc && node_path) {
node = node_object_new(id, type, version, &interface_node_events, &interface_core_events); node = node_object_new(id, type, version, &interface_node_events, &interface_core_events);
if (node == NULL) { if (!node) {
SDL_SetError("Pipewire: Failed to allocate interface node"); SDL_SetError("Pipewire: Failed to allocate interface node");
return; return;
} }
@ -687,7 +687,7 @@ static void registry_event_global_callback(void *object, uint32_t id, uint32_t p
desc_buffer_len = SDL_strlen(node_desc) + 1; desc_buffer_len = SDL_strlen(node_desc) + 1;
path_buffer_len = SDL_strlen(node_path) + 1; path_buffer_len = SDL_strlen(node_path) + 1;
node->userdata = io = SDL_calloc(1, sizeof(struct io_node) + desc_buffer_len + path_buffer_len); node->userdata = io = SDL_calloc(1, sizeof(struct io_node) + desc_buffer_len + path_buffer_len);
if (io == NULL) { if (!io) {
node_object_destroy(node); node_object_destroy(node);
SDL_OutOfMemory(); SDL_OutOfMemory();
return; return;
@ -708,7 +708,7 @@ static void registry_event_global_callback(void *object, uint32_t id, uint32_t p
} }
} else if (!SDL_strcmp(type, PW_TYPE_INTERFACE_Metadata)) { } else if (!SDL_strcmp(type, PW_TYPE_INTERFACE_Metadata)) {
node = node_object_new(id, type, version, &metadata_node_events, &metadata_core_events); node = node_object_new(id, type, version, &metadata_node_events, &metadata_core_events);
if (node == NULL) { if (!node) {
SDL_SetError("Pipewire: Failed to allocate metadata node"); SDL_SetError("Pipewire: Failed to allocate metadata node");
return; return;
} }
@ -736,22 +736,22 @@ static int hotplug_loop_init(void)
spa_list_init(&hotplug_io_list); spa_list_init(&hotplug_io_list);
hotplug_loop = PIPEWIRE_pw_thread_loop_new("SDLAudioHotplug", NULL); hotplug_loop = PIPEWIRE_pw_thread_loop_new("SDLAudioHotplug", NULL);
if (hotplug_loop == NULL) { if (!hotplug_loop) {
return SDL_SetError("Pipewire: Failed to create hotplug detection loop (%i)", errno); return SDL_SetError("Pipewire: Failed to create hotplug detection loop (%i)", errno);
} }
hotplug_context = PIPEWIRE_pw_context_new(PIPEWIRE_pw_thread_loop_get_loop(hotplug_loop), NULL, 0); hotplug_context = PIPEWIRE_pw_context_new(PIPEWIRE_pw_thread_loop_get_loop(hotplug_loop), NULL, 0);
if (hotplug_context == NULL) { if (!hotplug_context) {
return SDL_SetError("Pipewire: Failed to create hotplug detection context (%i)", errno); return SDL_SetError("Pipewire: Failed to create hotplug detection context (%i)", errno);
} }
hotplug_core = PIPEWIRE_pw_context_connect(hotplug_context, NULL, 0); hotplug_core = PIPEWIRE_pw_context_connect(hotplug_context, NULL, 0);
if (hotplug_core == NULL) { if (!hotplug_core) {
return SDL_SetError("Pipewire: Failed to connect hotplug detection context (%i)", errno); return SDL_SetError("Pipewire: Failed to connect hotplug detection context (%i)", errno);
} }
hotplug_registry = pw_core_get_registry(hotplug_core, PW_VERSION_REGISTRY, 0); hotplug_registry = pw_core_get_registry(hotplug_core, PW_VERSION_REGISTRY, 0);
if (hotplug_registry == NULL) { if (!hotplug_registry) {
return SDL_SetError("Pipewire: Failed to acquire hotplug detection registry (%i)", errno); return SDL_SetError("Pipewire: Failed to acquire hotplug detection registry (%i)", errno);
} }
@ -783,11 +783,11 @@ static void hotplug_loop_destroy(void)
hotplug_init_complete = SDL_FALSE; hotplug_init_complete = SDL_FALSE;
hotplug_events_enabled = SDL_FALSE; hotplug_events_enabled = SDL_FALSE;
if (pipewire_default_sink_id != NULL) { if (pipewire_default_sink_id) {
SDL_free(pipewire_default_sink_id); SDL_free(pipewire_default_sink_id);
pipewire_default_sink_id = NULL; pipewire_default_sink_id = NULL;
} }
if (pipewire_default_source_id != NULL) { if (pipewire_default_source_id) {
SDL_free(pipewire_default_source_id); SDL_free(pipewire_default_source_id);
pipewire_default_source_id = NULL; pipewire_default_source_id = NULL;
} }
@ -826,10 +826,10 @@ static void PIPEWIRE_DetectDevices(SDL_AudioDevice **default_output, SDL_AudioDe
spa_list_for_each (io, &hotplug_io_list, link) { spa_list_for_each (io, &hotplug_io_list, link) {
SDL_AudioDevice *device = SDL_AddAudioDevice(io->is_capture, io->name, &io->spec, PW_ID_TO_HANDLE(io->id)); SDL_AudioDevice *device = SDL_AddAudioDevice(io->is_capture, io->name, &io->spec, PW_ID_TO_HANDLE(io->id));
if (pipewire_default_sink_id != NULL && SDL_strcmp(io->path, pipewire_default_sink_id) == 0) { if (pipewire_default_sink_id && SDL_strcmp(io->path, pipewire_default_sink_id) == 0) {
SDL_assert(!io->is_capture); SDL_assert(!io->is_capture);
*default_output = device; *default_output = device;
} else if (pipewire_default_source_id != NULL && SDL_strcmp(io->path, pipewire_default_source_id) == 0) { } else if (pipewire_default_source_id && SDL_strcmp(io->path, pipewire_default_source_id) == 0) {
SDL_assert(io->is_capture); SDL_assert(io->is_capture);
*default_capture = device; *default_capture = device;
} }
@ -965,7 +965,7 @@ static void PIPEWIRE_FlushCapture(SDL_AudioDevice *device)
{ {
struct pw_stream *stream = device->hidden->stream; struct pw_stream *stream = device->hidden->stream;
struct pw_buffer *pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream); struct pw_buffer *pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream);
if (pw_buf != NULL) { // just requeue it without any further thought. if (pw_buf) { // just requeue it without any further thought.
PIPEWIRE_pw_stream_queue_buffer(stream, pw_buf); PIPEWIRE_pw_stream_queue_buffer(stream, pw_buf);
} }
} }
@ -1062,7 +1062,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
struct SDL_PrivateAudioData *priv; struct SDL_PrivateAudioData *priv;
struct pw_properties *props; struct pw_properties *props;
const char *app_name, *app_id, *stream_name, *stream_role, *error; const char *app_name, *app_id, *stream_name, *stream_role, *error;
Uint32 node_id = device->handle == NULL ? PW_ID_ANY : PW_HANDLE_TO_ID(device->handle); Uint32 node_id = !device->handle ? PW_ID_ANY : PW_HANDLE_TO_ID(device->handle);
const SDL_bool iscapture = device->iscapture; const SDL_bool iscapture = device->iscapture;
int res; int res;
@ -1071,9 +1071,9 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
// Get the hints for the application name, stream name and role // Get the hints for the application name, stream name and role
app_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME); app_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME);
if (app_name == NULL || *app_name == '\0') { if (!app_name || *app_name == '\0') {
app_name = SDL_GetHint(SDL_HINT_APP_NAME); app_name = SDL_GetHint(SDL_HINT_APP_NAME);
if (app_name == NULL || *app_name == '\0') { if (!app_name || *app_name == '\0') {
app_name = "SDL Application"; app_name = "SDL Application";
} }
} }
@ -1082,7 +1082,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
app_id = SDL_GetHint(SDL_HINT_APP_ID); app_id = SDL_GetHint(SDL_HINT_APP_ID);
stream_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_NAME); stream_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_NAME);
if (stream_name == NULL || *stream_name == '\0') { if (!stream_name || *stream_name == '\0') {
stream_name = "Audio Stream"; stream_name = "Audio Stream";
} }
@ -1091,20 +1091,20 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
* but 'Game' seems more appropriate for the majority of SDL applications. * but 'Game' seems more appropriate for the majority of SDL applications.
*/ */
stream_role = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_ROLE); stream_role = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_ROLE);
if (stream_role == NULL || *stream_role == '\0') { if (!stream_role || *stream_role == '\0') {
stream_role = "Game"; stream_role = "Game";
} }
// Initialize the Pipewire stream info from the SDL audio spec // Initialize the Pipewire stream info from the SDL audio spec
initialize_spa_info(&device->spec, &spa_info); initialize_spa_info(&device->spec, &spa_info);
params = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &spa_info); params = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &spa_info);
if (params == NULL) { if (!params) {
return SDL_SetError("Pipewire: Failed to set audio format parameters"); return SDL_SetError("Pipewire: Failed to set audio format parameters");
} }
priv = SDL_calloc(1, sizeof(struct SDL_PrivateAudioData)); priv = SDL_calloc(1, sizeof(struct SDL_PrivateAudioData));
device->hidden = priv; device->hidden = priv;
if (priv == NULL) { if (!priv) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -1119,23 +1119,23 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
SDL_GetAudioThreadName(device, thread_name, sizeof(thread_name)); SDL_GetAudioThreadName(device, thread_name, sizeof(thread_name));
priv->loop = PIPEWIRE_pw_thread_loop_new(thread_name, NULL); priv->loop = PIPEWIRE_pw_thread_loop_new(thread_name, NULL);
if (priv->loop == NULL) { if (!priv->loop) {
return SDL_SetError("Pipewire: Failed to create stream loop (%i)", errno); return SDL_SetError("Pipewire: Failed to create stream loop (%i)", errno);
} }
// Load the realtime module so Pipewire can set the loop thread to the appropriate priority. // Load the realtime module so Pipewire can set the loop thread to the appropriate priority.
props = PIPEWIRE_pw_properties_new(PW_KEY_CONFIG_NAME, "client-rt.conf", NULL); props = PIPEWIRE_pw_properties_new(PW_KEY_CONFIG_NAME, "client-rt.conf", NULL);
if (props == NULL) { if (!props) {
return SDL_SetError("Pipewire: Failed to create stream context properties (%i)", errno); return SDL_SetError("Pipewire: Failed to create stream context properties (%i)", errno);
} }
priv->context = PIPEWIRE_pw_context_new(PIPEWIRE_pw_thread_loop_get_loop(priv->loop), props, 0); priv->context = PIPEWIRE_pw_context_new(PIPEWIRE_pw_thread_loop_get_loop(priv->loop), props, 0);
if (priv->context == NULL) { if (!priv->context) {
return SDL_SetError("Pipewire: Failed to create stream context (%i)", errno); return SDL_SetError("Pipewire: Failed to create stream context (%i)", errno);
} }
props = PIPEWIRE_pw_properties_new(NULL, NULL); props = PIPEWIRE_pw_properties_new(NULL, NULL);
if (props == NULL) { if (!props) {
return SDL_SetError("Pipewire: Failed to create stream properties (%i)", errno); return SDL_SetError("Pipewire: Failed to create stream properties (%i)", errno);
} }
@ -1143,7 +1143,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
PIPEWIRE_pw_properties_set(props, PW_KEY_MEDIA_CATEGORY, iscapture ? "Capture" : "Playback"); PIPEWIRE_pw_properties_set(props, PW_KEY_MEDIA_CATEGORY, iscapture ? "Capture" : "Playback");
PIPEWIRE_pw_properties_set(props, PW_KEY_MEDIA_ROLE, stream_role); PIPEWIRE_pw_properties_set(props, PW_KEY_MEDIA_ROLE, stream_role);
PIPEWIRE_pw_properties_set(props, PW_KEY_APP_NAME, app_name); PIPEWIRE_pw_properties_set(props, PW_KEY_APP_NAME, app_name);
if (app_id != NULL) { if (app_id) {
PIPEWIRE_pw_properties_set(props, PW_KEY_APP_ID, app_id); PIPEWIRE_pw_properties_set(props, PW_KEY_APP_ID, app_id);
} }
PIPEWIRE_pw_properties_set(props, PW_KEY_NODE_NAME, stream_name); PIPEWIRE_pw_properties_set(props, PW_KEY_NODE_NAME, stream_name);
@ -1165,7 +1165,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
PIPEWIRE_pw_thread_loop_lock(hotplug_loop); PIPEWIRE_pw_thread_loop_lock(hotplug_loop);
node = io_list_get_by_id(node_id); node = io_list_get_by_id(node_id);
if (node != NULL) { if (node) {
PIPEWIRE_pw_properties_set(props, PW_KEY_TARGET_OBJECT, node->path); PIPEWIRE_pw_properties_set(props, PW_KEY_TARGET_OBJECT, node->path);
} }
PIPEWIRE_pw_thread_loop_unlock(hotplug_loop); PIPEWIRE_pw_thread_loop_unlock(hotplug_loop);
@ -1177,7 +1177,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
// Create the new stream // Create the new stream
priv->stream = PIPEWIRE_pw_stream_new_simple(PIPEWIRE_pw_thread_loop_get_loop(priv->loop), stream_name, props, priv->stream = PIPEWIRE_pw_stream_new_simple(PIPEWIRE_pw_thread_loop_get_loop(priv->loop), stream_name, props,
iscapture ? &stream_input_events : &stream_output_events, device); iscapture ? &stream_input_events : &stream_output_events, device);
if (priv->stream == NULL) { if (!priv->stream) {
return SDL_SetError("Pipewire: Failed to create stream (%i)", errno); return SDL_SetError("Pipewire: Failed to create stream (%i)", errno);
} }

View File

@ -30,7 +30,7 @@
static int PS2AUDIO_OpenDevice(SDL_AudioDevice *device) static int PS2AUDIO_OpenDevice(SDL_AudioDevice *device)
{ {
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -73,7 +73,7 @@ static int PS2AUDIO_OpenDevice(SDL_AudioDevice *device)
64, so spec->size should be a multiple of 64 as well. */ 64, so spec->size should be a multiple of 64 as well. */
const int mixlen = device->buffer_size * NUM_BUFFERS; const int mixlen = device->buffer_size * NUM_BUFFERS;
device->hidden->rawbuf = (Uint8 *)SDL_aligned_alloc(64, mixlen); device->hidden->rawbuf = (Uint8 *)SDL_aligned_alloc(64, mixlen);
if (device->hidden->rawbuf == NULL) { if (!device->hidden->rawbuf) {
return SDL_SetError("Couldn't allocate mixing buffer"); return SDL_SetError("Couldn't allocate mixing buffer");
} }
@ -112,7 +112,7 @@ static void PS2AUDIO_CloseDevice(SDL_AudioDevice *device)
device->hidden->channel = -1; device->hidden->channel = -1;
} }
if (device->hidden->rawbuf != NULL) { if (device->hidden->rawbuf) {
SDL_aligned_free(device->hidden->rawbuf); SDL_aligned_free(device->hidden->rawbuf);
device->hidden->rawbuf = NULL; device->hidden->rawbuf = NULL;
} }

View File

@ -41,7 +41,7 @@ static inline SDL_bool isBasicAudioConfig(const SDL_AudioSpec *spec)
static int PSPAUDIO_OpenDevice(SDL_AudioDevice *device) static int PSPAUDIO_OpenDevice(SDL_AudioDevice *device)
{ {
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -93,7 +93,7 @@ static int PSPAUDIO_OpenDevice(SDL_AudioDevice *device)
64, so spec->size should be a multiple of 64 as well. */ 64, so spec->size should be a multiple of 64 as well. */
const int mixlen = device->buffer_size * NUM_BUFFERS; const int mixlen = device->buffer_size * NUM_BUFFERS;
device->hidden->rawbuf = (Uint8 *)SDL_aligned_alloc(64, mixlen); device->hidden->rawbuf = (Uint8 *)SDL_aligned_alloc(64, mixlen);
if (device->hidden->rawbuf == NULL) { if (!device->hidden->rawbuf) {
return SDL_SetError("Couldn't allocate mixing buffer"); return SDL_SetError("Couldn't allocate mixing buffer");
} }
@ -141,7 +141,7 @@ static void PSPAUDIO_CloseDevice(SDL_AudioDevice *device)
device->hidden->channel = -1; device->hidden->channel = -1;
} }
if (device->hidden->rawbuf != NULL) { if (device->hidden->rawbuf) {
SDL_aligned_free(device->hidden->rawbuf); SDL_aligned_free(device->hidden->rawbuf);
device->hidden->rawbuf = NULL; device->hidden->rawbuf = NULL;
} }

View File

@ -135,7 +135,7 @@ static void *pulseaudio_handle = NULL;
static int load_pulseaudio_sym(const char *fn, void **addr) static int load_pulseaudio_sym(const char *fn, void **addr)
{ {
*addr = SDL_LoadFunction(pulseaudio_handle, fn); *addr = SDL_LoadFunction(pulseaudio_handle, fn);
if (*addr == NULL) { if (!*addr) {
// Don't call SDL_SetError(): SDL_LoadFunction already did. // Don't call SDL_SetError(): SDL_LoadFunction already did.
return 0; return 0;
} }
@ -150,7 +150,7 @@ static int load_pulseaudio_sym(const char *fn, void **addr)
static void UnloadPulseAudioLibrary(void) static void UnloadPulseAudioLibrary(void)
{ {
if (pulseaudio_handle != NULL) { if (pulseaudio_handle) {
SDL_UnloadObject(pulseaudio_handle); SDL_UnloadObject(pulseaudio_handle);
pulseaudio_handle = NULL; pulseaudio_handle = NULL;
} }
@ -159,9 +159,9 @@ static void UnloadPulseAudioLibrary(void)
static int LoadPulseAudioLibrary(void) static int LoadPulseAudioLibrary(void)
{ {
int retval = 0; int retval = 0;
if (pulseaudio_handle == NULL) { if (!pulseaudio_handle) {
pulseaudio_handle = SDL_LoadObject(pulseaudio_library); pulseaudio_handle = SDL_LoadObject(pulseaudio_library);
if (pulseaudio_handle == NULL) { if (!pulseaudio_handle) {
retval = -1; retval = -1;
// Don't call SDL_SetError(): SDL_LoadObject already did. // Don't call SDL_SetError(): SDL_LoadObject already did.
} else { } else {
@ -275,7 +275,7 @@ static const char *getAppName(void)
} else { } else {
const char *verstr = PULSEAUDIO_pa_get_library_version(); const char *verstr = PULSEAUDIO_pa_get_library_version();
retval = "SDL Application"; // the "oh well" default. retval = "SDL Application"; // the "oh well" default.
if (verstr != NULL) { if (verstr) {
int maj, min, patch; int maj, min, patch;
if (SDL_sscanf(verstr, "%d.%d.%d", &maj, &min, &patch) == 3) { if (SDL_sscanf(verstr, "%d.%d.%d", &maj, &min, &patch) == 3) {
if (squashVersion(maj, min, patch) >= squashVersion(0, 9, 15)) { if (squashVersion(maj, min, patch) >= squashVersion(0, 9, 15)) {
@ -297,13 +297,13 @@ static void OperationStateChangeCallback(pa_operation *o, void *userdata)
static void WaitForPulseOperation(pa_operation *o) static void WaitForPulseOperation(pa_operation *o)
{ {
// This checks for NO errors currently. Either fix that, check results elsewhere, or do things you don't care about. // This checks for NO errors currently. Either fix that, check results elsewhere, or do things you don't care about.
SDL_assert(pulseaudio_threaded_mainloop != NULL); SDL_assert(pulseaudio_threaded_mainloop);
if (o) { if (o) {
// note that if PULSEAUDIO_pa_operation_set_state_callback == NULL, then `o` must have a callback that will signal pulseaudio_threaded_mainloop. // note that if PULSEAUDIO_pa_operation_set_state_callback == NULL, then `o` must have a callback that will signal pulseaudio_threaded_mainloop.
// If not, on really old (earlier PulseAudio 4.0, from the year 2013!) installs, this call will block forever. // If not, on really old (earlier PulseAudio 4.0, from the year 2013!) installs, this call will block forever.
// On more modern installs, we won't ever block forever, and maybe be more efficient, thanks to pa_operation_set_state_callback. // On more modern installs, we won't ever block forever, and maybe be more efficient, thanks to pa_operation_set_state_callback.
// WARNING: at the time of this writing: the Steam Runtime is still on PulseAudio 1.1! // WARNING: at the time of this writing: the Steam Runtime is still on PulseAudio 1.1!
if (PULSEAUDIO_pa_operation_set_state_callback != NULL) { if (PULSEAUDIO_pa_operation_set_state_callback) {
PULSEAUDIO_pa_operation_set_state_callback(o, OperationStateChangeCallback, NULL); PULSEAUDIO_pa_operation_set_state_callback(o, OperationStateChangeCallback, NULL);
} }
while (PULSEAUDIO_pa_operation_get_state(o) == PA_OPERATION_RUNNING) { while (PULSEAUDIO_pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
@ -315,7 +315,7 @@ static void WaitForPulseOperation(pa_operation *o)
static void DisconnectFromPulseServer(void) static void DisconnectFromPulseServer(void)
{ {
if (pulseaudio_threaded_mainloop != NULL) { if (pulseaudio_threaded_mainloop) {
PULSEAUDIO_pa_threaded_mainloop_stop(pulseaudio_threaded_mainloop); PULSEAUDIO_pa_threaded_mainloop_stop(pulseaudio_threaded_mainloop);
} }
if (pulseaudio_context) { if (pulseaudio_context) {
@ -323,7 +323,7 @@ static void DisconnectFromPulseServer(void)
PULSEAUDIO_pa_context_unref(pulseaudio_context); PULSEAUDIO_pa_context_unref(pulseaudio_context);
pulseaudio_context = NULL; pulseaudio_context = NULL;
} }
if (pulseaudio_threaded_mainloop != NULL) { if (pulseaudio_threaded_mainloop) {
PULSEAUDIO_pa_threaded_mainloop_free(pulseaudio_threaded_mainloop); PULSEAUDIO_pa_threaded_mainloop_free(pulseaudio_threaded_mainloop);
pulseaudio_threaded_mainloop = NULL; pulseaudio_threaded_mainloop = NULL;
} }
@ -339,8 +339,8 @@ static int ConnectToPulseServer(void)
pa_mainloop_api *mainloop_api = NULL; pa_mainloop_api *mainloop_api = NULL;
int state = 0; int state = 0;
SDL_assert(pulseaudio_threaded_mainloop == NULL); SDL_assert(!pulseaudio_threaded_mainloop);
SDL_assert(pulseaudio_context == NULL); SDL_assert(!pulseaudio_context);
// Set up a new main loop // Set up a new main loop
if (!(pulseaudio_threaded_mainloop = PULSEAUDIO_pa_threaded_mainloop_new())) { if (!(pulseaudio_threaded_mainloop = PULSEAUDIO_pa_threaded_mainloop_new())) {
@ -363,7 +363,7 @@ static int ConnectToPulseServer(void)
SDL_assert(mainloop_api); // this never fails, right? SDL_assert(mainloop_api); // this never fails, right?
pulseaudio_context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName()); pulseaudio_context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName());
if (pulseaudio_context == NULL) { if (!pulseaudio_context) {
SDL_SetError("pa_context_new() failed"); SDL_SetError("pa_context_new() failed");
goto failed; goto failed;
} }
@ -480,7 +480,7 @@ static int PULSEAUDIO_WaitCaptureDevice(SDL_AudioDevice *device)
{ {
struct SDL_PrivateAudioData *h = device->hidden; struct SDL_PrivateAudioData *h = device->hidden;
if (h->capturebuf != NULL) { if (h->capturebuf) {
return 0; // there's still data available to read. return 0; // there's still data available to read.
} }
@ -500,7 +500,7 @@ static int PULSEAUDIO_WaitCaptureDevice(SDL_AudioDevice *device)
size_t nbytes = 0; size_t nbytes = 0;
PULSEAUDIO_pa_stream_peek(h->stream, &data, &nbytes); PULSEAUDIO_pa_stream_peek(h->stream, &data, &nbytes);
SDL_assert(nbytes > 0); SDL_assert(nbytes > 0);
if (data == NULL) { // If NULL, then the buffer had a hole, ignore that if (!data) { // If NULL, then the buffer had a hole, ignore that
PULSEAUDIO_pa_stream_drop(h->stream); // drop this fragment. PULSEAUDIO_pa_stream_drop(h->stream); // drop this fragment.
} else { } else {
// store this fragment's data for use with CaptureFromDevice // store this fragment's data for use with CaptureFromDevice
@ -521,7 +521,7 @@ static int PULSEAUDIO_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, i
{ {
struct SDL_PrivateAudioData *h = device->hidden; struct SDL_PrivateAudioData *h = device->hidden;
if (h->capturebuf != NULL) { if (h->capturebuf) {
const int cpy = SDL_min(buflen, h->capturelen); const int cpy = SDL_min(buflen, h->capturelen);
if (cpy > 0) { if (cpy > 0) {
//SDL_Log("PULSEAUDIO: fed %d captured bytes", cpy); //SDL_Log("PULSEAUDIO: fed %d captured bytes", cpy);
@ -549,7 +549,7 @@ static void PULSEAUDIO_FlushCapture(SDL_AudioDevice *device)
PULSEAUDIO_pa_threaded_mainloop_lock(pulseaudio_threaded_mainloop); PULSEAUDIO_pa_threaded_mainloop_lock(pulseaudio_threaded_mainloop);
if (h->capturebuf != NULL) { if (h->capturebuf) {
PULSEAUDIO_pa_stream_drop(h->stream); PULSEAUDIO_pa_stream_drop(h->stream);
h->capturebuf = NULL; h->capturebuf = NULL;
h->capturelen = 0; h->capturelen = 0;
@ -578,7 +578,7 @@ static void PULSEAUDIO_CloseDevice(SDL_AudioDevice *device)
PULSEAUDIO_pa_threaded_mainloop_lock(pulseaudio_threaded_mainloop); PULSEAUDIO_pa_threaded_mainloop_lock(pulseaudio_threaded_mainloop);
if (device->hidden->stream) { if (device->hidden->stream) {
if (device->hidden->capturebuf != NULL) { if (device->hidden->capturebuf) {
PULSEAUDIO_pa_stream_drop(device->hidden->stream); PULSEAUDIO_pa_stream_drop(device->hidden->stream);
} }
PULSEAUDIO_pa_stream_disconnect(device->hidden->stream); PULSEAUDIO_pa_stream_disconnect(device->hidden->stream);
@ -609,12 +609,12 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device)
int format = PA_SAMPLE_INVALID; int format = PA_SAMPLE_INVALID;
int retval = 0; int retval = 0;
SDL_assert(pulseaudio_threaded_mainloop != NULL); SDL_assert(pulseaudio_threaded_mainloop);
SDL_assert(pulseaudio_context != NULL); SDL_assert(pulseaudio_context);
// Initialize all variables that we clean on shutdown // Initialize all variables that we clean on shutdown
h = device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); h = device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -663,7 +663,7 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device)
// Allocate mixing buffer // Allocate mixing buffer
if (!iscapture) { if (!iscapture) {
h->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); h->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
if (h->mixbuf == NULL) { if (!h->mixbuf) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(h->mixbuf, device->silence_value, device->buffer_size); SDL_memset(h->mixbuf, device->silence_value, device->buffer_size);
@ -694,7 +694,7 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device)
&pacmap // channel map &pacmap // channel map
); );
if (h->stream == NULL) { if (!h->stream) {
retval = SDL_SetError("Could not set up PulseAudio stream"); retval = SDL_SetError("Could not set up PulseAudio stream");
} else { } else {
int rc; int rc;

View File

@ -176,7 +176,7 @@ static Uint8 *QSA_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
static void QSA_CloseDevice(SDL_AudioDevice *device) static void QSA_CloseDevice(SDL_AudioDevice *device)
{ {
if (device->hidden) { if (device->hidden) {
if (device->hidden->audio_handle != NULL) { if (device->hidden->audio_handle) {
#if _NTO_VERSION < 710 #if _NTO_VERSION < 710
// Finish playing available samples or cancel unread samples during capture // Finish playing available samples or cancel unread samples during capture
snd_pcm_plugin_flush(device->hidden->audio_handle, device->iscapture ? SND_PCM_CHANNEL_CAPTURE : SND_PCM_CHANNEL_PLAYBACK); snd_pcm_plugin_flush(device->hidden->audio_handle, device->iscapture ? SND_PCM_CHANNEL_CAPTURE : SND_PCM_CHANNEL_PLAYBACK);

View File

@ -71,7 +71,7 @@ static void *sndio_handle = NULL;
static int load_sndio_sym(const char *fn, void **addr) static int load_sndio_sym(const char *fn, void **addr)
{ {
*addr = SDL_LoadFunction(sndio_handle, fn); *addr = SDL_LoadFunction(sndio_handle, fn);
if (*addr == NULL) { if (!*addr) {
return 0; // Don't call SDL_SetError(): SDL_LoadFunction already did. return 0; // Don't call SDL_SetError(): SDL_LoadFunction already did.
} }
@ -110,7 +110,7 @@ static int load_sndio_syms(void)
static void UnloadSNDIOLibrary(void) static void UnloadSNDIOLibrary(void)
{ {
if (sndio_handle != NULL) { if (sndio_handle) {
SDL_UnloadObject(sndio_handle); SDL_UnloadObject(sndio_handle);
sndio_handle = NULL; sndio_handle = NULL;
} }
@ -119,9 +119,9 @@ static void UnloadSNDIOLibrary(void)
static int LoadSNDIOLibrary(void) static int LoadSNDIOLibrary(void)
{ {
int retval = 0; int retval = 0;
if (sndio_handle == NULL) { if (!sndio_handle) {
sndio_handle = SDL_LoadObject(sndio_library); sndio_handle = SDL_LoadObject(sndio_library);
if (sndio_handle == NULL) { if (!sndio_handle) {
retval = -1; // Don't call SDL_SetError(): SDL_LoadObject already did. retval = -1; // Don't call SDL_SetError(): SDL_LoadObject already did.
} else { } else {
retval = load_sndio_syms(); retval = load_sndio_syms();
@ -213,7 +213,7 @@ static Uint8 *SNDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
static void SNDIO_CloseDevice(SDL_AudioDevice *device) static void SNDIO_CloseDevice(SDL_AudioDevice *device)
{ {
if (device->hidden) { if (device->hidden) {
if (device->hidden->dev != NULL) { if (device->hidden->dev) {
SNDIO_sio_stop(device->hidden->dev); SNDIO_sio_stop(device->hidden->dev);
SNDIO_sio_close(device->hidden->dev); SNDIO_sio_close(device->hidden->dev);
} }
@ -227,7 +227,7 @@ static void SNDIO_CloseDevice(SDL_AudioDevice *device)
static int SNDIO_OpenDevice(SDL_AudioDevice *device) static int SNDIO_OpenDevice(SDL_AudioDevice *device)
{ {
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -235,14 +235,14 @@ static int SNDIO_OpenDevice(SDL_AudioDevice *device)
const char *audiodev = SDL_getenv("AUDIODEV"); const char *audiodev = SDL_getenv("AUDIODEV");
// Capture devices must be non-blocking for SNDIO_FlushCapture // Capture devices must be non-blocking for SNDIO_FlushCapture
device->hidden->dev = SNDIO_sio_open(audiodev != NULL ? audiodev : SIO_DEVANY, device->hidden->dev = SNDIO_sio_open(audiodev ? audiodev : SIO_DEVANY,
device->iscapture ? SIO_REC : SIO_PLAY, device->iscapture); device->iscapture ? SIO_REC : SIO_PLAY, device->iscapture);
if (device->hidden->dev == NULL) { if (!device->hidden->dev) {
return SDL_SetError("sio_open() failed"); return SDL_SetError("sio_open() failed");
} }
device->hidden->pfd = SDL_malloc(sizeof(struct pollfd) * SNDIO_sio_nfds(device->hidden->dev)); device->hidden->pfd = SDL_malloc(sizeof(struct pollfd) * SNDIO_sio_nfds(device->hidden->dev));
if (device->hidden->pfd == NULL) { if (!device->hidden->pfd) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -307,7 +307,7 @@ static int SNDIO_OpenDevice(SDL_AudioDevice *device)
// Allocate mixing buffer // Allocate mixing buffer
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
if (device->hidden->mixbuf == NULL) { if (!device->hidden->mixbuf) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);

View File

@ -63,7 +63,7 @@ static int VITAAUD_OpenDevice(SDL_AudioDevice *device)
device->hidden = (struct SDL_PrivateAudioData *) device->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc(sizeof(*device->hidden)); SDL_malloc(sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(device->hidden, 0, sizeof(*device->hidden)); SDL_memset(device->hidden, 0, sizeof(*device->hidden));
@ -95,7 +95,7 @@ static int VITAAUD_OpenDevice(SDL_AudioDevice *device)
64, so spec->size should be a multiple of 64 as well. */ 64, so spec->size should be a multiple of 64 as well. */
mixlen = device->buffer_size * NUM_BUFFERS; mixlen = device->buffer_size * NUM_BUFFERS;
device->hidden->rawbuf = (Uint8 *)SDL_aligned_alloc(64, mixlen); device->hidden->rawbuf = (Uint8 *)SDL_aligned_alloc(64, mixlen);
if (device->hidden->rawbuf == NULL) { if (!device->hidden->rawbuf) {
return SDL_SetError("Couldn't allocate mixing buffer"); return SDL_SetError("Couldn't allocate mixing buffer");
} }
@ -163,7 +163,7 @@ static void VITAAUD_CloseDevice(SDL_AudioDevice *device)
device->hidden->port = -1; device->hidden->port = -1;
} }
if (!device->iscapture && device->hidden->rawbuf != NULL) { if (!device->iscapture && device->hidden->rawbuf) {
SDL_aligned_free(device->hidden->rawbuf); // this uses SDL_aligned_alloc(), not SDL_malloc() SDL_aligned_free(device->hidden->rawbuf); // this uses SDL_aligned_alloc(), not SDL_malloc()
device->hidden->rawbuf = NULL; device->hidden->rawbuf = NULL;
} }

View File

@ -93,7 +93,7 @@ static void ManagementThreadMainloop(void)
int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, int *wait_on_result) int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, int *wait_on_result)
{ {
// We want to block for a result, but we are already running from the management thread! Just run the task now so we don't deadlock. // We want to block for a result, but we are already running from the management thread! Just run the task now so we don't deadlock.
if ((wait_on_result != NULL) && (SDL_ThreadID() == SDL_GetThreadID(ManagementThread))) { if ((wait_on_result) && (SDL_ThreadID() == SDL_GetThreadID(ManagementThread))) {
*wait_on_result = task(userdata); *wait_on_result = task(userdata);
return 0; // completed! return 0; // completed!
} }
@ -124,11 +124,11 @@ int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, in
// add to end of task list. // add to end of task list.
ManagementThreadPendingTask *prev = NULL; ManagementThreadPendingTask *prev = NULL;
for (ManagementThreadPendingTask *i = SDL_AtomicGetPtr((void **) &ManagementThreadPendingTasks); i != NULL; i = i->next) { for (ManagementThreadPendingTask *i = SDL_AtomicGetPtr((void **) &ManagementThreadPendingTasks); i; i = i->next) {
prev = i; prev = i;
} }
if (prev != NULL) { if (prev) {
prev->next = pending; prev->next = pending;
} else { } else {
SDL_AtomicSetPtr((void **) &ManagementThreadPendingTasks, pending); SDL_AtomicSetPtr((void **) &ManagementThreadPendingTasks, pending);
@ -413,7 +413,7 @@ static Uint8 *WASAPI_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
if (device->hidden->render) { if (device->hidden->render) {
if (WasapiFailed(device, IAudioRenderClient_GetBuffer(device->hidden->render, device->sample_frames, &buffer))) { if (WasapiFailed(device, IAudioRenderClient_GetBuffer(device->hidden->render, device->sample_frames, &buffer))) {
SDL_assert(buffer == NULL); SDL_assert(!buffer);
if (device->hidden->device_lost) { // just use an available buffer, we won't be playing it anyhow. if (device->hidden->device_lost) { // just use an available buffer, we won't be playing it anyhow.
*buffer_size = 0; // we'll recover during WaitDevice and try again. *buffer_size = 0; // we'll recover during WaitDevice and try again.
} }
@ -425,7 +425,7 @@ static Uint8 *WASAPI_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
static int WASAPI_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) static int WASAPI_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
{ {
if (device->hidden->render != NULL) { // definitely activated? if (device->hidden->render) { // definitely activated?
// WasapiFailed() will mark the device for reacquisition or removal elsewhere. // WasapiFailed() will mark the device for reacquisition or removal elsewhere.
WasapiFailed(device, IAudioRenderClient_ReleaseBuffer(device->hidden->render, device->sample_frames, 0)); WasapiFailed(device, IAudioRenderClient_ReleaseBuffer(device->hidden->render, device->sample_frames, 0));
} }
@ -542,7 +542,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
const AUDCLNT_SHAREMODE sharemode = AUDCLNT_SHAREMODE_SHARED; const AUDCLNT_SHAREMODE sharemode = AUDCLNT_SHAREMODE_SHARED;
IAudioClient *client = device->hidden->client; IAudioClient *client = device->hidden->client;
SDL_assert(client != NULL); SDL_assert(client);
#if defined(__WINRT__) || defined(__GDK__) // CreateEventEx() arrived in Vista, so we need an #ifdef for XP. #if defined(__WINRT__) || defined(__GDK__) // CreateEventEx() arrived in Vista, so we need an #ifdef for XP.
device->hidden->event = CreateEventEx(NULL, NULL, 0, EVENT_ALL_ACCESS); device->hidden->event = CreateEventEx(NULL, NULL, 0, EVENT_ALL_ACCESS);
@ -550,7 +550,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
device->hidden->event = CreateEventW(NULL, 0, 0, NULL); device->hidden->event = CreateEventW(NULL, 0, 0, NULL);
#endif #endif
if (device->hidden->event == NULL) { if (!device->hidden->event) {
return WIN_SetError("WASAPI can't create an event handle"); return WIN_SetError("WASAPI can't create an event handle");
} }
@ -561,7 +561,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
if (FAILED(ret)) { if (FAILED(ret)) {
return WIN_SetErrorFromHRESULT("WASAPI can't determine mix format", ret); return WIN_SetErrorFromHRESULT("WASAPI can't determine mix format", ret);
} }
SDL_assert(waveformat != NULL); SDL_assert(waveformat);
device->hidden->waveformat = waveformat; device->hidden->waveformat = waveformat;
SDL_AudioSpec newspec; SDL_AudioSpec newspec;
@ -642,7 +642,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
return WIN_SetErrorFromHRESULT("WASAPI can't get capture client service", ret); return WIN_SetErrorFromHRESULT("WASAPI can't get capture client service", ret);
} }
SDL_assert(capture != NULL); SDL_assert(capture);
device->hidden->capture = capture; device->hidden->capture = capture;
ret = IAudioClient_Start(client); ret = IAudioClient_Start(client);
if (FAILED(ret)) { if (FAILED(ret)) {
@ -657,7 +657,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
return WIN_SetErrorFromHRESULT("WASAPI can't get render client service", ret); return WIN_SetErrorFromHRESULT("WASAPI can't get render client service", ret);
} }
SDL_assert(render != NULL); SDL_assert(render);
device->hidden->render = render; device->hidden->render = render;
ret = IAudioClient_Start(client); ret = IAudioClient_Start(client);
if (FAILED(ret)) { if (FAILED(ret)) {
@ -679,7 +679,7 @@ static int WASAPI_OpenDevice(SDL_AudioDevice *device)
{ {
// Initialize all variables that we clean on shutdown // Initialize all variables that we clean on shutdown
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
if (device->hidden == NULL) { if (!device->hidden) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} else if (ActivateWasapiDevice(device) < 0) { } else if (ActivateWasapiDevice(device) < 0) {
return -1; // already set error. return -1; // already set error.

View File

@ -164,11 +164,11 @@ int WASAPI_ActivateDevice(SDL_AudioDevice *device)
IMMDevice_Release(immdevice); IMMDevice_Release(immdevice);
if (FAILED(ret)) { if (FAILED(ret)) {
SDL_assert(device->hidden->client == NULL); SDL_assert(!device->hidden->client);
return WIN_SetErrorFromHRESULT("WASAPI can't activate audio endpoint", ret); return WIN_SetErrorFromHRESULT("WASAPI can't activate audio endpoint", ret);
} }
SDL_assert(device->hidden->client != NULL); SDL_assert(device->hidden->client);
if (WASAPI_PrepDevice(device) == -1) { // not async, fire it right away. if (WASAPI_PrepDevice(device) == -1) { // not async, fire it right away.
return -1; return -1;
} }

View File

@ -32,7 +32,7 @@ SDL_RunApp(int argc, char* argv[], SDL_main_func mainFunction, void * reserved)
(void)reserved; (void)reserved;
if(argv == NULL) if(!argv)
{ {
argc = 0; argc = 0;
/* make sure argv isn't NULL, in case some user code doesn't like that */ /* make sure argv isn't NULL, in case some user code doesn't like that */

View File

@ -434,12 +434,12 @@ JNIEnv *Android_JNI_GetEnv(void)
{ {
/* Get JNIEnv from the Thread local storage */ /* Get JNIEnv from the Thread local storage */
JNIEnv *env = pthread_getspecific(mThreadKey); JNIEnv *env = pthread_getspecific(mThreadKey);
if (env == NULL) { if (!env) {
/* If it fails, try to attach ! (e.g the thread isn't created with SDL_CreateThread() */ /* If it fails, try to attach ! (e.g the thread isn't created with SDL_CreateThread() */
int status; int status;
/* There should be a JVM */ /* There should be a JVM */
if (mJavaVM == NULL) { if (!mJavaVM) {
__android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed, there is no JavaVM"); __android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed, there is no JavaVM");
return NULL; return NULL;
} }
@ -468,7 +468,7 @@ int Android_JNI_SetupThread(void)
int status; int status;
/* There should be a JVM */ /* There should be a JVM */
if (mJavaVM == NULL) { if (!mJavaVM) {
__android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed, there is no JavaVM"); __android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed, there is no JavaVM");
return 0; return 0;
} }
@ -494,7 +494,7 @@ static void Android_JNI_ThreadDestroyed(void *value)
{ {
/* The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required */ /* The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required */
JNIEnv *env = (JNIEnv *)value; JNIEnv *env = (JNIEnv *)value;
if (env != NULL) { if (env) {
(*mJavaVM)->DetachCurrentThread(mJavaVM); (*mJavaVM)->DetachCurrentThread(mJavaVM);
Android_JNI_SetEnv(NULL); Android_JNI_SetEnv(NULL);
} }
@ -520,7 +520,7 @@ static void Android_JNI_CreateKey_once(void)
static void register_methods(JNIEnv *env, const char *classname, JNINativeMethod *methods, int nb) static void register_methods(JNIEnv *env, const char *classname, JNINativeMethod *methods, int nb)
{ {
jclass clazz = (*env)->FindClass(env, classname); jclass clazz = (*env)->FindClass(env, classname);
if (clazz == NULL || (*env)->RegisterNatives(env, clazz, methods, nb) < 0) { if (!clazz || (*env)->RegisterNatives(env, clazz, methods, nb) < 0) {
__android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed to register methods of %s", classname); __android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed to register methods of %s", classname);
return; return;
} }
@ -582,28 +582,28 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
/* Save JNIEnv of SDLActivity */ /* Save JNIEnv of SDLActivity */
Android_JNI_SetEnv(env); Android_JNI_SetEnv(env);
if (mJavaVM == NULL) { if (!mJavaVM) {
__android_log_print(ANDROID_LOG_ERROR, "SDL", "failed to found a JavaVM"); __android_log_print(ANDROID_LOG_ERROR, "SDL", "failed to found a JavaVM");
} }
/* Use a mutex to prevent concurrency issues between Java Activity and Native thread code, when using 'Android_Window'. /* Use a mutex to prevent concurrency issues between Java Activity and Native thread code, when using 'Android_Window'.
* (Eg. Java sending Touch events, while native code is destroying the main SDL_Window. ) * (Eg. Java sending Touch events, while native code is destroying the main SDL_Window. )
*/ */
if (Android_ActivityMutex == NULL) { if (!Android_ActivityMutex) {
Android_ActivityMutex = SDL_CreateMutex(); /* Could this be created twice if onCreate() is called a second time ? */ Android_ActivityMutex = SDL_CreateMutex(); /* Could this be created twice if onCreate() is called a second time ? */
} }
if (Android_ActivityMutex == NULL) { if (!Android_ActivityMutex) {
__android_log_print(ANDROID_LOG_ERROR, "SDL", "failed to create Android_ActivityMutex mutex"); __android_log_print(ANDROID_LOG_ERROR, "SDL", "failed to create Android_ActivityMutex mutex");
} }
Android_PauseSem = SDL_CreateSemaphore(0); Android_PauseSem = SDL_CreateSemaphore(0);
if (Android_PauseSem == NULL) { if (!Android_PauseSem) {
__android_log_print(ANDROID_LOG_ERROR, "SDL", "failed to create Android_PauseSem semaphore"); __android_log_print(ANDROID_LOG_ERROR, "SDL", "failed to create Android_PauseSem semaphore");
} }
Android_ResumeSem = SDL_CreateSemaphore(0); Android_ResumeSem = SDL_CreateSemaphore(0);
if (Android_ResumeSem == NULL) { if (!Android_ResumeSem) {
__android_log_print(ANDROID_LOG_ERROR, "SDL", "failed to create Android_ResumeSem semaphore"); __android_log_print(ANDROID_LOG_ERROR, "SDL", "failed to create Android_ResumeSem semaphore");
} }
@ -1614,7 +1614,7 @@ int Android_JNI_OpenAudioDevice(SDL_AudioDevice *device)
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for output"); __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for output");
result = (*env)->CallStaticObjectMethod(env, mAudioManagerClass, midAudioOpen, spec->freq, audioformat, spec->channels, device->sample_frames, device_id); result = (*env)->CallStaticObjectMethod(env, mAudioManagerClass, midAudioOpen, spec->freq, audioformat, spec->channels, device->sample_frames, device_id);
} }
if (result == NULL) { if (!result) {
/* Error during audio initialization, error printed from Java */ /* Error during audio initialization, error printed from Java */
return SDL_SetError("Java-side initialization failed"); return SDL_SetError("Java-side initialization failed");
} }
@ -1675,7 +1675,7 @@ int Android_JNI_OpenAudioDevice(SDL_AudioDevice *device)
return SDL_SetError("Unexpected audio format from Java: %d\n", audioformat); return SDL_SetError("Unexpected audio format from Java: %d\n", audioformat);
} }
if (jbufobj == NULL) { if (!jbufobj) {
__android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: could not allocate an audio buffer"); __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: could not allocate an audio buffer");
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -1946,7 +1946,7 @@ static void Internal_Android_Create_AssetManager()
javaAssetManagerRef = (*env)->NewGlobalRef(env, javaAssetManager); javaAssetManagerRef = (*env)->NewGlobalRef(env, javaAssetManager);
asset_manager = AAssetManager_fromJava(env, javaAssetManagerRef); asset_manager = AAssetManager_fromJava(env, javaAssetManagerRef);
if (asset_manager == NULL) { if (!asset_manager) {
(*env)->DeleteGlobalRef(env, javaAssetManagerRef); (*env)->DeleteGlobalRef(env, javaAssetManagerRef);
Android_JNI_ExceptionOccurred(SDL_TRUE); Android_JNI_ExceptionOccurred(SDL_TRUE);
} }
@ -1970,16 +1970,16 @@ int Android_JNI_FileOpen(SDL_RWops *ctx,
AAsset *asset = NULL; AAsset *asset = NULL;
ctx->hidden.androidio.asset = NULL; ctx->hidden.androidio.asset = NULL;
if (asset_manager == NULL) { if (!asset_manager) {
Internal_Android_Create_AssetManager(); Internal_Android_Create_AssetManager();
} }
if (asset_manager == NULL) { if (!asset_manager) {
return SDL_SetError("Couldn't create asset manager"); return SDL_SetError("Couldn't create asset manager");
} }
asset = AAssetManager_open(asset_manager, fileName, AASSET_MODE_UNKNOWN); asset = AAssetManager_open(asset_manager, fileName, AASSET_MODE_UNKNOWN);
if (asset == NULL) { if (!asset) {
return SDL_SetError("Couldn't open asset '%s'", fileName); return SDL_SetError("Couldn't open asset '%s'", fileName);
} }
@ -2051,7 +2051,7 @@ char *Android_JNI_GetClipboardText(void)
(*env)->DeleteLocalRef(env, string); (*env)->DeleteLocalRef(env, string);
} }
return (text == NULL) ? SDL_strdup("") : text; return (!text) ? SDL_strdup("") : text;
} }
SDL_bool Android_JNI_HasClipboardText(void) SDL_bool Android_JNI_HasClipboardText(void)
@ -2371,7 +2371,7 @@ void *SDL_AndroidGetActivity(void)
/* See SDL_system.h for caveats on using this function. */ /* See SDL_system.h for caveats on using this function. */
JNIEnv *env = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
if (env == NULL) { if (!env) {
return NULL; return NULL;
} }
@ -2425,7 +2425,7 @@ const char *SDL_AndroidGetInternalStoragePath(void)
{ {
static char *s_AndroidInternalFilesPath = NULL; static char *s_AndroidInternalFilesPath = NULL;
if (s_AndroidInternalFilesPath == NULL) { if (!s_AndroidInternalFilesPath) {
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__); struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
jmethodID mid; jmethodID mid;
jobject context; jobject context;
@ -2524,7 +2524,7 @@ const char *SDL_AndroidGetExternalStoragePath(void)
{ {
static char *s_AndroidExternalFilesPath = NULL; static char *s_AndroidExternalFilesPath = NULL;
if (s_AndroidExternalFilesPath == NULL) { if (!s_AndroidExternalFilesPath) {
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__); struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
jmethodID mid; jmethodID mid;
jobject context; jobject context;
@ -2680,16 +2680,16 @@ int Android_JNI_GetLocale(char *buf, size_t buflen)
/* Need to re-create the asset manager if locale has changed (SDL_EVENT_LOCALE_CHANGED) */ /* Need to re-create the asset manager if locale has changed (SDL_EVENT_LOCALE_CHANGED) */
Internal_Android_Destroy_AssetManager(); Internal_Android_Destroy_AssetManager();
if (asset_manager == NULL) { if (!asset_manager) {
Internal_Android_Create_AssetManager(); Internal_Android_Create_AssetManager();
} }
if (asset_manager == NULL) { if (!asset_manager) {
return -1; return -1;
} }
cfg = AConfiguration_new(); cfg = AConfiguration_new();
if (cfg == NULL) { if (!cfg) {
return -1; return -1;
} }

View File

@ -87,7 +87,7 @@ static void kbd_cleanup(void)
{ {
struct mouse_info mData; struct mouse_info mData;
SDL_EVDEV_keyboard_state *kbd = kbd_cleanup_state; SDL_EVDEV_keyboard_state *kbd = kbd_cleanup_state;
if (kbd == NULL) { if (!kbd) {
return; return;
} }
kbd_cleanup_state = NULL; kbd_cleanup_state = NULL;
@ -178,7 +178,7 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state *kbd)
{ {
int tabidx; int tabidx;
if (kbd_cleanup_state != NULL) { if (kbd_cleanup_state) {
return; return;
} }
kbd_cleanup_state = kbd; kbd_cleanup_state = kbd;
@ -230,7 +230,7 @@ SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void)
SDL_zero(mData); SDL_zero(mData);
mData.operation = MOUSE_HIDE; mData.operation = MOUSE_HIDE;
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state)); kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state));
if (kbd == NULL) { if (!kbd) {
return NULL; return NULL;
} }
@ -296,7 +296,7 @@ void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
{ {
struct mouse_info mData; struct mouse_info mData;
if (kbd == NULL) { if (!kbd) {
return; return;
} }
SDL_zero(mData); SDL_zero(mData);
@ -486,7 +486,7 @@ void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode,
unsigned int final_key_state; unsigned int final_key_state;
unsigned int map_from_key_sym; unsigned int map_from_key_sym;
if (kbd == NULL) { if (!kbd) {
return; return;
} }

View File

@ -108,13 +108,13 @@ static int StartBeLooper()
{ {
if (!be_app) { if (!be_app) {
SDL_AppThread = SDL_CreateThreadInternal(StartBeApp, "SDLApplication", 0, NULL); SDL_AppThread = SDL_CreateThreadInternal(StartBeApp, "SDLApplication", 0, NULL);
if (SDL_AppThread == NULL) { if (!SDL_AppThread) {
return SDL_SetError("Couldn't create BApplication thread"); return SDL_SetError("Couldn't create BApplication thread");
} }
do { do {
SDL_Delay(10); SDL_Delay(10);
} while ((be_app == NULL) || be_app->IsLaunching()); } while ((!be_app) || be_app->IsLaunching());
} }
/* Change working directory to that of executable */ /* Change working directory to that of executable */
@ -167,7 +167,7 @@ void SDL_QuitBeApp(void)
SDL_Looper->Lock(); SDL_Looper->Lock();
SDL_Looper->Quit(); SDL_Looper->Quit();
SDL_Looper = NULL; SDL_Looper = NULL;
if (SDL_AppThread != NULL) { if (SDL_AppThread) {
if (be_app != NULL) { /* Not tested */ if (be_app != NULL) { /* Not tested */
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
} }

View File

@ -96,7 +96,7 @@ static int LoadDBUSSyms(void)
static void UnloadDBUSLibrary(void) static void UnloadDBUSLibrary(void)
{ {
if (dbus_handle != NULL) { if (dbus_handle) {
SDL_UnloadObject(dbus_handle); SDL_UnloadObject(dbus_handle);
dbus_handle = NULL; dbus_handle = NULL;
} }
@ -105,9 +105,9 @@ static void UnloadDBUSLibrary(void)
static int LoadDBUSLibrary(void) static int LoadDBUSLibrary(void)
{ {
int retval = 0; int retval = 0;
if (dbus_handle == NULL) { if (!dbus_handle) {
dbus_handle = SDL_LoadObject(dbus_library); dbus_handle = SDL_LoadObject(dbus_library);
if (dbus_handle == NULL) { if (!dbus_handle) {
retval = -1; retval = -1;
/* Don't call SDL_SetError(): SDL_LoadObject already did. */ /* Don't call SDL_SetError(): SDL_LoadObject already did. */
} else { } else {
@ -199,7 +199,7 @@ void SDL_DBus_Quit(void)
SDL_DBusContext *SDL_DBus_GetContext(void) SDL_DBusContext *SDL_DBus_GetContext(void)
{ {
if (dbus_handle == NULL || !dbus.session_conn) { if (!dbus_handle || !dbus.session_conn) {
SDL_DBus_Init(); SDL_DBus_Init();
} }
@ -360,7 +360,7 @@ SDL_bool SDL_DBus_QueryProperty(const char *node, const char *path, const char *
void SDL_DBus_ScreensaverTickle(void) void SDL_DBus_ScreensaverTickle(void)
{ {
if (screensaver_cookie == 0 && inhibit_handle == NULL) { /* no need to tickle if we're inhibiting. */ if (screensaver_cookie == 0 && !inhibit_handle) { /* no need to tickle if we're inhibiting. */
/* org.gnome.ScreenSaver is the legacy interface, but it'll either do nothing or just be a second harmless tickle on newer systems, so we leave it for now. */ /* org.gnome.ScreenSaver is the legacy interface, but it'll either do nothing or just be a second harmless tickle on newer systems, so we leave it for now. */
SDL_DBus_CallVoidMethod("org.gnome.ScreenSaver", "/org/gnome/ScreenSaver", "org.gnome.ScreenSaver", "SimulateUserActivity", DBUS_TYPE_INVALID); SDL_DBus_CallVoidMethod("org.gnome.ScreenSaver", "/org/gnome/ScreenSaver", "org.gnome.ScreenSaver", "SimulateUserActivity", DBUS_TYPE_INVALID);
SDL_DBus_CallVoidMethod("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver", "org.freedesktop.ScreenSaver", "SimulateUserActivity", DBUS_TYPE_INVALID); SDL_DBus_CallVoidMethod("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver", "org.freedesktop.ScreenSaver", "SimulateUserActivity", DBUS_TYPE_INVALID);
@ -428,7 +428,7 @@ SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
{ {
const char *default_inhibit_reason = "Playing a game"; const char *default_inhibit_reason = "Playing a game";
if ((inhibit && (screensaver_cookie != 0 || inhibit_handle != NULL)) || (!inhibit && (screensaver_cookie == 0 && inhibit_handle == NULL))) { if ((inhibit && (screensaver_cookie != 0 || inhibit_handle)) || (!inhibit && (screensaver_cookie == 0 && !inhibit_handle))) {
return SDL_TRUE; return SDL_TRUE;
} }
@ -452,12 +452,12 @@ SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
const char *key = "reason"; const char *key = "reason";
const char *reply = NULL; const char *reply = NULL;
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME); const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
if (reason == NULL || !reason[0]) { if (!reason || !reason[0]) {
reason = default_inhibit_reason; reason = default_inhibit_reason;
} }
msg = dbus.message_new_method_call(bus_name, path, interface, "Inhibit"); msg = dbus.message_new_method_call(bus_name, path, interface, "Inhibit");
if (msg == NULL) { if (!msg) {
return SDL_FALSE; return SDL_FALSE;
} }
@ -496,10 +496,10 @@ SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
if (inhibit) { if (inhibit) {
const char *app = SDL_GetHint(SDL_HINT_APP_NAME); const char *app = SDL_GetHint(SDL_HINT_APP_NAME);
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME); const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
if (app == NULL || !app[0]) { if (!app || !app[0]) {
app = "My SDL application"; app = "My SDL application";
} }
if (reason == NULL || !reason[0]) { if (!reason || !reason[0]) {
reason = default_inhibit_reason; reason = default_inhibit_reason;
} }

View File

@ -167,9 +167,9 @@ static void SDL_EVDEV_UpdateKeyboardMute(void)
int SDL_EVDEV_Init(void) int SDL_EVDEV_Init(void)
{ {
if (_this == NULL) { if (!_this) {
_this = (SDL_EVDEV_PrivateData *)SDL_calloc(1, sizeof(*_this)); _this = (SDL_EVDEV_PrivateData *)SDL_calloc(1, sizeof(*_this));
if (_this == NULL) { if (!_this) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -231,7 +231,7 @@ int SDL_EVDEV_Init(void)
void SDL_EVDEV_Quit(void) void SDL_EVDEV_Quit(void)
{ {
if (_this == NULL) { if (!_this) {
return; return;
} }
@ -244,14 +244,14 @@ void SDL_EVDEV_Quit(void)
#endif /* SDL_USE_LIBUDEV */ #endif /* SDL_USE_LIBUDEV */
/* Remove existing devices */ /* Remove existing devices */
while (_this->first != NULL) { while (_this->first) {
SDL_EVDEV_device_removed(_this->first->path); SDL_EVDEV_device_removed(_this->first->path);
} }
SDL_EVDEV_kbd_quit(_this->kbd); SDL_EVDEV_kbd_quit(_this->kbd);
SDL_assert(_this->first == NULL); SDL_assert(!_this->first);
SDL_assert(_this->last == NULL); SDL_assert(!_this->last);
SDL_assert(_this->num_devices == 0); SDL_assert(_this->num_devices == 0);
SDL_free(_this); SDL_free(_this);
@ -263,7 +263,7 @@ void SDL_EVDEV_Quit(void)
static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_class, static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_class,
const char *dev_path) const char *dev_path)
{ {
if (dev_path == NULL) { if (!dev_path) {
return; return;
} }
@ -301,7 +301,7 @@ int SDL_EVDEV_GetDeviceCount(int device_class)
SDL_evdevlist_item *item; SDL_evdevlist_item *item;
int count = 0; int count = 0;
for (item = _this->first; item != NULL; item = item->next) { for (item = _this->first; item; item = item->next) {
if ((item->udev_class & device_class) == device_class) { if ((item->udev_class & device_class) == device_class) {
++count; ++count;
} }
@ -331,7 +331,7 @@ void SDL_EVDEV_Poll(void)
mouse = SDL_GetMouse(); mouse = SDL_GetMouse();
for (item = _this->first; item != NULL; item = item->next) { for (item = _this->first; item; item = item->next) {
while ((len = read(item->fd, events, sizeof(events))) > 0) { while ((len = read(item->fd, events, sizeof(events))) > 0) {
len /= sizeof(events[0]); len /= sizeof(events[0]);
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
@ -643,7 +643,7 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
} }
item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data)); item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data));
if (item->touchscreen_data == NULL) { if (!item->touchscreen_data) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -654,7 +654,7 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
} }
item->touchscreen_data->name = SDL_strdup(name); item->touchscreen_data->name = SDL_strdup(name);
if (item->touchscreen_data->name == NULL) { if (!item->touchscreen_data->name) {
SDL_free(item->touchscreen_data); SDL_free(item->touchscreen_data);
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -709,7 +709,7 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
item->touchscreen_data->slots = SDL_calloc( item->touchscreen_data->slots = SDL_calloc(
item->touchscreen_data->max_slots, item->touchscreen_data->max_slots,
sizeof(*item->touchscreen_data->slots)); sizeof(*item->touchscreen_data->slots));
if (item->touchscreen_data->slots == NULL) { if (!item->touchscreen_data->slots) {
SDL_free(item->touchscreen_data->name); SDL_free(item->touchscreen_data->name);
SDL_free(item->touchscreen_data); SDL_free(item->touchscreen_data);
return SDL_OutOfMemory(); return SDL_OutOfMemory();
@ -770,7 +770,7 @@ static void SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
sizeof(*mt_req_values) * item->touchscreen_data->max_slots; sizeof(*mt_req_values) * item->touchscreen_data->max_slots;
mt_req_code = SDL_calloc(1, mt_req_size); mt_req_code = SDL_calloc(1, mt_req_size);
if (mt_req_code == NULL) { if (!mt_req_code) {
return; return;
} }
@ -875,14 +875,14 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class)
unsigned long relbit[NBITS(REL_MAX)] = { 0 }; unsigned long relbit[NBITS(REL_MAX)] = { 0 };
/* Check to make sure it's not already in list. */ /* Check to make sure it's not already in list. */
for (item = _this->first; item != NULL; item = item->next) { for (item = _this->first; item; item = item->next) {
if (SDL_strcmp(dev_path, item->path) == 0) { if (SDL_strcmp(dev_path, item->path) == 0) {
return -1; /* already have this one */ return -1; /* already have this one */
} }
} }
item = (SDL_evdevlist_item *)SDL_calloc(1, sizeof(SDL_evdevlist_item)); item = (SDL_evdevlist_item *)SDL_calloc(1, sizeof(SDL_evdevlist_item));
if (item == NULL) { if (!item) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -893,7 +893,7 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class)
} }
item->path = SDL_strdup(dev_path); item->path = SDL_strdup(dev_path);
if (item->path == NULL) { if (!item->path) {
close(item->fd); close(item->fd);
SDL_free(item); SDL_free(item);
return SDL_OutOfMemory(); return SDL_OutOfMemory();
@ -928,7 +928,7 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class)
} }
} }
if (_this->last == NULL) { if (!_this->last) {
_this->first = _this->last = item; _this->first = _this->last = item;
} else { } else {
_this->last->next = item; _this->last->next = item;
@ -947,10 +947,10 @@ static int SDL_EVDEV_device_removed(const char *dev_path)
SDL_evdevlist_item *item; SDL_evdevlist_item *item;
SDL_evdevlist_item *prev = NULL; SDL_evdevlist_item *prev = NULL;
for (item = _this->first; item != NULL; item = item->next) { for (item = _this->first; item; item = item->next) {
/* found it, remove it. */ /* found it, remove it. */
if (SDL_strcmp(dev_path, item->path) == 0) { if (SDL_strcmp(dev_path, item->path) == 0) {
if (prev != NULL) { if (prev) {
prev->next = item->next; prev->next = item->next;
} else { } else {
SDL_assert(_this->first == item); SDL_assert(_this->first == item);

View File

@ -173,7 +173,7 @@ static int fatal_signals[] = {
static void kbd_cleanup(void) static void kbd_cleanup(void)
{ {
SDL_EVDEV_keyboard_state *kbd = kbd_cleanup_state; SDL_EVDEV_keyboard_state *kbd = kbd_cleanup_state;
if (kbd == NULL) { if (!kbd) {
return; return;
} }
kbd_cleanup_state = NULL; kbd_cleanup_state = NULL;
@ -258,7 +258,7 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state *kbd)
{ {
int tabidx; int tabidx;
if (kbd_cleanup_state != NULL) { if (kbd_cleanup_state) {
return; return;
} }
kbd_cleanup_state = kbd; kbd_cleanup_state = kbd;
@ -428,7 +428,7 @@ SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void)
char shift_state[sizeof(long)] = { TIOCL_GETSHIFTSTATE, 0 }; char shift_state[sizeof(long)] = { TIOCL_GETSHIFTSTATE, 0 };
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd)); kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd));
if (kbd == NULL) { if (!kbd) {
return NULL; return NULL;
} }
@ -464,7 +464,7 @@ SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void)
void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, SDL_bool muted) void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, SDL_bool muted)
{ {
if (state == NULL) { if (!state) {
return; return;
} }
@ -892,7 +892,7 @@ void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode
unsigned short *key_map; unsigned short *key_map;
unsigned short keysym; unsigned short keysym;
if (state == NULL) { if (!state) {
return; return;
} }
@ -900,7 +900,7 @@ void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode
shift_final = (state->shift_state | state->slockstate) ^ state->lockstate; shift_final = (state->shift_state | state->slockstate) ^ state->lockstate;
key_map = state->key_maps[shift_final]; key_map = state->key_maps[shift_final];
if (key_map == NULL) { if (!key_map) {
/* Unsupported shift state (e.g. ctrl = 4, alt = 8), just reset to the default state */ /* Unsupported shift state (e.g. ctrl = 4, alt = 8), just reset to the default state */
state->shift_state = 0; state->shift_state = 0;
state->slockstate = 0; state->slockstate = 0;

View File

@ -419,7 +419,7 @@ void SDL_Fcitx_UpdateTextRect(const SDL_Rect *rect)
} }
focused_win = SDL_GetKeyboardFocus(); focused_win = SDL_GetKeyboardFocus();
if (focused_win == NULL) { if (!focused_win) {
return; return;
} }

View File

@ -112,7 +112,7 @@ static SDL_bool IBus_EnterVariant(DBusConnection *conn, DBusMessageIter *iter, S
} }
dbus->message_iter_get_basic(inside, &struct_id); dbus->message_iter_get_basic(inside, &struct_id);
if (struct_id == NULL || SDL_strncmp(struct_id, struct_id, id_size) != 0) { if (!struct_id || SDL_strncmp(struct_id, struct_id, id_size) != 0) {
return SDL_FALSE; return SDL_FALSE;
} }
return SDL_TRUE; return SDL_TRUE;
@ -291,7 +291,7 @@ static char *IBus_ReadAddressFromFile(const char *file_path)
FILE *addr_file; FILE *addr_file;
addr_file = fopen(file_path, "r"); addr_file = fopen(file_path, "r");
if (addr_file == NULL) { if (!addr_file) {
return NULL; return NULL;
} }
@ -336,7 +336,7 @@ static char *IBus_GetDBusAddressFilename(void)
} }
dbus = SDL_DBus_GetContext(); dbus = SDL_DBus_GetContext();
if (dbus == NULL) { if (!dbus) {
return NULL; return NULL;
} }
@ -350,7 +350,7 @@ static char *IBus_GetDBusAddressFilename(void)
and look up the address from a filepath using all those bits, eek. */ and look up the address from a filepath using all those bits, eek. */
disp_env = SDL_getenv("DISPLAY"); disp_env = SDL_getenv("DISPLAY");
if (disp_env == NULL || !*disp_env) { if (!disp_env || !*disp_env) {
display = SDL_strdup(":0.0"); display = SDL_strdup(":0.0");
} else { } else {
display = SDL_strdup(disp_env); display = SDL_strdup(disp_env);
@ -360,7 +360,7 @@ static char *IBus_GetDBusAddressFilename(void)
disp_num = SDL_strrchr(display, ':'); disp_num = SDL_strrchr(display, ':');
screen_num = SDL_strrchr(display, '.'); screen_num = SDL_strrchr(display, '.');
if (disp_num == NULL) { if (!disp_num) {
SDL_free(display); SDL_free(display);
return NULL; return NULL;
} }
@ -374,7 +374,7 @@ static char *IBus_GetDBusAddressFilename(void)
if (!*host) { if (!*host) {
const char *session = SDL_getenv("XDG_SESSION_TYPE"); const char *session = SDL_getenv("XDG_SESSION_TYPE");
if (session != NULL && SDL_strcmp(session, "wayland") == 0) { if (session && SDL_strcmp(session, "wayland") == 0) {
host = "unix-wayland"; host = "unix-wayland";
} else { } else {
host = "unix"; host = "unix";
@ -388,7 +388,7 @@ static char *IBus_GetDBusAddressFilename(void)
SDL_strlcpy(config_dir, conf_env, sizeof(config_dir)); SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
} else { } else {
const char *home_env = SDL_getenv("HOME"); const char *home_env = SDL_getenv("HOME");
if (home_env == NULL || !*home_env) { if (!home_env || !*home_env) {
SDL_free(display); SDL_free(display);
return NULL; return NULL;
} }
@ -397,7 +397,7 @@ static char *IBus_GetDBusAddressFilename(void)
key = SDL_DBus_GetLocalMachineId(); key = SDL_DBus_GetLocalMachineId();
if (key == NULL) { if (!key) {
SDL_free(display); SDL_free(display);
return NULL; return NULL;
} }
@ -458,7 +458,7 @@ static SDL_bool IBus_SetupConnection(SDL_DBusContext *dbus, const char *addr)
ibus_input_interface = IBUS_INPUT_INTERFACE; ibus_input_interface = IBUS_INPUT_INTERFACE;
ibus_conn = dbus->connection_open_private(addr, NULL); ibus_conn = dbus->connection_open_private(addr, NULL);
if (ibus_conn == NULL) { if (!ibus_conn) {
return SDL_FALSE; /* oh well. */ return SDL_FALSE; /* oh well. */
} }
@ -498,7 +498,7 @@ static SDL_bool IBus_SetupConnection(SDL_DBusContext *dbus, const char *addr)
static SDL_bool IBus_CheckConnection(SDL_DBusContext *dbus) static SDL_bool IBus_CheckConnection(SDL_DBusContext *dbus)
{ {
if (dbus == NULL) { if (!dbus) {
return SDL_FALSE; return SDL_FALSE;
} }
@ -518,7 +518,7 @@ static SDL_bool IBus_CheckConnection(SDL_DBusContext *dbus)
struct inotify_event *event = (struct inotify_event *)p; struct inotify_event *event = (struct inotify_event *)p;
if (event->len > 0) { if (event->len > 0) {
char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/'); char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/');
if (addr_file_no_path == NULL) { if (!addr_file_no_path) {
return SDL_FALSE; return SDL_FALSE;
} }
@ -555,12 +555,12 @@ SDL_bool SDL_IBus_Init(void)
char *addr; char *addr;
char *addr_file_dir; char *addr_file_dir;
if (addr_file == NULL) { if (!addr_file) {
return SDL_FALSE; return SDL_FALSE;
} }
addr = IBus_ReadAddressFromFile(addr_file); addr = IBus_ReadAddressFromFile(addr_file);
if (addr == NULL) { if (!addr) {
SDL_free(addr_file); SDL_free(addr_file);
return SDL_FALSE; return SDL_FALSE;
} }
@ -646,7 +646,7 @@ static void IBus_SimpleMessage(const char *method)
{ {
SDL_DBusContext *dbus = SDL_DBus_GetContext(); SDL_DBusContext *dbus = SDL_DBus_GetContext();
if ((input_ctx_path != NULL) && (IBus_CheckConnection(dbus))) { if ((input_ctx_path) && (IBus_CheckConnection(dbus))) {
SDL_DBus_CallVoidMethodOnConnection(ibus_conn, ibus_service, input_ctx_path, ibus_input_interface, method, DBUS_TYPE_INVALID); SDL_DBus_CallVoidMethodOnConnection(ibus_conn, ibus_service, input_ctx_path, ibus_input_interface, method, DBUS_TYPE_INVALID);
} }
} }
@ -696,7 +696,7 @@ void SDL_IBus_UpdateTextRect(const SDL_Rect *rect)
} }
focused_win = SDL_GetKeyboardFocus(); focused_win = SDL_GetKeyboardFocus();
if (focused_win == NULL) { if (!focused_win) {
return; return;
} }

View File

@ -56,9 +56,9 @@ static void InitIME(void)
/* See if fcitx IME support is being requested */ /* See if fcitx IME support is being requested */
#ifdef HAVE_FCITX #ifdef HAVE_FCITX
if (SDL_IME_Init_Real == NULL && if (!SDL_IME_Init_Real &&
((im_module && SDL_strcmp(im_module, "fcitx") == 0) || ((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||
(im_module == NULL && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) { (!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
SDL_IME_Init_Real = SDL_Fcitx_Init; SDL_IME_Init_Real = SDL_Fcitx_Init;
SDL_IME_Quit_Real = SDL_Fcitx_Quit; SDL_IME_Quit_Real = SDL_Fcitx_Quit;
SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus; SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
@ -71,7 +71,7 @@ static void InitIME(void)
/* default to IBus */ /* default to IBus */
#ifdef HAVE_IBUS_IBUS_H #ifdef HAVE_IBUS_IBUS_H
if (SDL_IME_Init_Real == NULL) { if (!SDL_IME_Init_Real) {
SDL_IME_Init_Real = SDL_IBus_Init; SDL_IME_Init_Real = SDL_IBus_Init;
SDL_IME_Quit_Real = SDL_IBus_Quit; SDL_IME_Quit_Real = SDL_IBus_Quit;
SDL_IME_SetFocus_Real = SDL_IBus_SetFocus; SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;

View File

@ -115,12 +115,12 @@ SDL_bool SDL_SystemTheme_Init(void)
system_theme_data.theme = SDL_SYSTEM_THEME_UNKNOWN; system_theme_data.theme = SDL_SYSTEM_THEME_UNKNOWN;
system_theme_data.dbus = dbus; system_theme_data.dbus = dbus;
if (dbus == NULL) { if (!dbus) {
return SDL_FALSE; return SDL_FALSE;
} }
msg = dbus->message_new_method_call(PORTAL_DESTINATION, PORTAL_PATH, PORTAL_INTERFACE, PORTAL_METHOD); msg = dbus->message_new_method_call(PORTAL_DESTINATION, PORTAL_PATH, PORTAL_INTERFACE, PORTAL_METHOD);
if (msg != NULL) { if (msg) {
if (dbus->message_append_args(msg, DBUS_TYPE_STRING, &namespace, DBUS_TYPE_STRING, &key, DBUS_TYPE_INVALID)) { if (dbus->message_append_args(msg, DBUS_TYPE_STRING, &namespace, DBUS_TYPE_STRING, &key, DBUS_TYPE_INVALID)) {
DBusMessage *reply = dbus->connection_send_with_reply_and_block(dbus->session_conn, msg, 300, NULL); DBusMessage *reply = dbus->connection_send_with_reply_and_block(dbus->session_conn, msg, 300, NULL);
if (reply) { if (reply) {

View File

@ -111,19 +111,19 @@ static void rtkit_initialize(void)
dbus_conn = get_rtkit_dbus_connection(); dbus_conn = get_rtkit_dbus_connection();
/* Try getting minimum nice level: this is often greater than PRIO_MIN (-20). */ /* Try getting minimum nice level: this is often greater than PRIO_MIN (-20). */
if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel", if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel",
DBUS_TYPE_INT32, &rtkit_min_nice_level)) { DBUS_TYPE_INT32, &rtkit_min_nice_level)) {
rtkit_min_nice_level = -20; rtkit_min_nice_level = -20;
} }
/* Try getting maximum realtime priority: this can be less than the POSIX default (99). */ /* Try getting maximum realtime priority: this can be less than the POSIX default (99). */
if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority", if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority",
DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) { DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) {
rtkit_max_realtime_priority = 99; rtkit_max_realtime_priority = 99;
} }
/* Try getting maximum rttime allowed by rtkit: exceeding this value will result in SIGKILL */ /* Try getting maximum rttime allowed by rtkit: exceeding this value will result in SIGKILL */
if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax", if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax",
DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) { DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) {
rtkit_max_rttime_usec = 200000; rtkit_max_rttime_usec = 200000;
} }
@ -202,7 +202,7 @@ static SDL_bool rtkit_setpriority_nice(pid_t thread, int nice_level)
nice = rtkit_min_nice_level; nice = rtkit_min_nice_level;
} }
if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn, if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn,
rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID", rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID",
DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID, DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID,
DBUS_TYPE_INVALID)) { DBUS_TYPE_INVALID)) {
@ -233,7 +233,7 @@ static SDL_bool rtkit_setpriority_realtime(pid_t thread, int rt_priority)
// go through to determine whether it really needs to fail or not. // go through to determine whether it really needs to fail or not.
rtkit_initialize_realtime_thread(); rtkit_initialize_realtime_thread();
if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn, if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn,
rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID", rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID",
DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID, DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID,
DBUS_TYPE_INVALID)) { DBUS_TYPE_INVALID)) {

View File

@ -47,7 +47,7 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev);
static SDL_bool SDL_UDEV_load_sym(const char *fn, void **addr) static SDL_bool SDL_UDEV_load_sym(const char *fn, void **addr)
{ {
*addr = SDL_LoadFunction(_this->udev_handle, fn); *addr = SDL_LoadFunction(_this->udev_handle, fn);
if (*addr == NULL) { if (!*addr) {
/* Don't call SDL_SetError(): SDL_LoadFunction already did. */ /* Don't call SDL_SetError(): SDL_LoadFunction already did. */
return SDL_FALSE; return SDL_FALSE;
} }
@ -96,7 +96,7 @@ static int SDL_UDEV_load_syms(void)
static SDL_bool SDL_UDEV_hotplug_update_available(void) static SDL_bool SDL_UDEV_hotplug_update_available(void)
{ {
if (_this->udev_mon != NULL) { if (_this->udev_mon) {
const int fd = _this->syms.udev_monitor_get_fd(_this->udev_mon); const int fd = _this->syms.udev_monitor_get_fd(_this->udev_mon);
if (SDL_IOReady(fd, SDL_IOR_READ, 0)) { if (SDL_IOReady(fd, SDL_IOR_READ, 0)) {
return SDL_TRUE; return SDL_TRUE;
@ -109,9 +109,9 @@ int SDL_UDEV_Init(void)
{ {
int retval = 0; int retval = 0;
if (_this == NULL) { if (!_this) {
_this = (SDL_UDEV_PrivateData *)SDL_calloc(1, sizeof(*_this)); _this = (SDL_UDEV_PrivateData *)SDL_calloc(1, sizeof(*_this));
if (_this == NULL) { if (!_this) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -126,13 +126,13 @@ int SDL_UDEV_Init(void)
*/ */
_this->udev = _this->syms.udev_new(); _this->udev = _this->syms.udev_new();
if (_this->udev == NULL) { if (!_this->udev) {
SDL_UDEV_Quit(); SDL_UDEV_Quit();
return SDL_SetError("udev_new() failed"); return SDL_SetError("udev_new() failed");
} }
_this->udev_mon = _this->syms.udev_monitor_new_from_netlink(_this->udev, "udev"); _this->udev_mon = _this->syms.udev_monitor_new_from_netlink(_this->udev, "udev");
if (_this->udev_mon == NULL) { if (!_this->udev_mon) {
SDL_UDEV_Quit(); SDL_UDEV_Quit();
return SDL_SetError("udev_monitor_new_from_netlink() failed"); return SDL_SetError("udev_monitor_new_from_netlink() failed");
} }
@ -152,7 +152,7 @@ int SDL_UDEV_Init(void)
void SDL_UDEV_Quit(void) void SDL_UDEV_Quit(void)
{ {
if (_this == NULL) { if (!_this) {
return; return;
} }
@ -160,17 +160,17 @@ void SDL_UDEV_Quit(void)
if (_this->ref_count < 1) { if (_this->ref_count < 1) {
if (_this->udev_mon != NULL) { if (_this->udev_mon) {
_this->syms.udev_monitor_unref(_this->udev_mon); _this->syms.udev_monitor_unref(_this->udev_mon);
_this->udev_mon = NULL; _this->udev_mon = NULL;
} }
if (_this->udev != NULL) { if (_this->udev) {
_this->syms.udev_unref(_this->udev); _this->syms.udev_unref(_this->udev);
_this->udev = NULL; _this->udev = NULL;
} }
/* Remove existing devices */ /* Remove existing devices */
while (_this->first != NULL) { while (_this->first) {
SDL_UDEV_CallbackList *item = _this->first; SDL_UDEV_CallbackList *item = _this->first;
_this->first = _this->first->next; _this->first = _this->first->next;
SDL_free(item); SDL_free(item);
@ -188,12 +188,12 @@ int SDL_UDEV_Scan(void)
struct udev_list_entry *devs = NULL; struct udev_list_entry *devs = NULL;
struct udev_list_entry *item = NULL; struct udev_list_entry *item = NULL;
if (_this == NULL) { if (!_this) {
return 0; return 0;
} }
enumerate = _this->syms.udev_enumerate_new(_this->udev); enumerate = _this->syms.udev_enumerate_new(_this->udev);
if (enumerate == NULL) { if (!enumerate) {
SDL_UDEV_Quit(); SDL_UDEV_Quit();
return SDL_SetError("udev_enumerate_new() failed"); return SDL_SetError("udev_enumerate_new() failed");
} }
@ -206,7 +206,7 @@ int SDL_UDEV_Scan(void)
for (item = devs; item; item = _this->syms.udev_list_entry_get_next(item)) { for (item = devs; item; item = _this->syms.udev_list_entry_get_next(item)) {
const char *path = _this->syms.udev_list_entry_get_name(item); const char *path = _this->syms.udev_list_entry_get_name(item);
struct udev_device *dev = _this->syms.udev_device_new_from_syspath(_this->udev, path); struct udev_device *dev = _this->syms.udev_device_new_from_syspath(_this->udev, path);
if (dev != NULL) { if (dev) {
device_event(SDL_UDEV_DEVICEADDED, dev); device_event(SDL_UDEV_DEVICEADDED, dev);
_this->syms.udev_device_unref(dev); _this->syms.udev_device_unref(dev);
} }
@ -223,12 +223,12 @@ SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16
struct udev_list_entry *item = NULL; struct udev_list_entry *item = NULL;
SDL_bool found = SDL_FALSE; SDL_bool found = SDL_FALSE;
if (_this == NULL) { if (!_this) {
return SDL_FALSE; return SDL_FALSE;
} }
enumerate = _this->syms.udev_enumerate_new(_this->udev); enumerate = _this->syms.udev_enumerate_new(_this->udev);
if (enumerate == NULL) { if (!enumerate) {
SDL_SetError("udev_enumerate_new() failed"); SDL_SetError("udev_enumerate_new() failed");
return SDL_FALSE; return SDL_FALSE;
} }
@ -238,7 +238,7 @@ SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16
for (item = devs; item && !found; item = _this->syms.udev_list_entry_get_next(item)) { for (item = devs; item && !found; item = _this->syms.udev_list_entry_get_next(item)) {
const char *path = _this->syms.udev_list_entry_get_name(item); const char *path = _this->syms.udev_list_entry_get_name(item);
struct udev_device *dev = _this->syms.udev_device_new_from_syspath(_this->udev, path); struct udev_device *dev = _this->syms.udev_device_new_from_syspath(_this->udev, path);
if (dev != NULL) { if (dev) {
const char *val = NULL; const char *val = NULL;
const char *existing_path; const char *existing_path;
@ -247,17 +247,17 @@ SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16
found = SDL_TRUE; found = SDL_TRUE;
val = _this->syms.udev_device_get_property_value(dev, "ID_VENDOR_ID"); val = _this->syms.udev_device_get_property_value(dev, "ID_VENDOR_ID");
if (val != NULL) { if (val) {
*vendor = (Uint16)SDL_strtol(val, NULL, 16); *vendor = (Uint16)SDL_strtol(val, NULL, 16);
} }
val = _this->syms.udev_device_get_property_value(dev, "ID_MODEL_ID"); val = _this->syms.udev_device_get_property_value(dev, "ID_MODEL_ID");
if (val != NULL) { if (val) {
*product = (Uint16)SDL_strtol(val, NULL, 16); *product = (Uint16)SDL_strtol(val, NULL, 16);
} }
val = _this->syms.udev_device_get_property_value(dev, "ID_REVISION"); val = _this->syms.udev_device_get_property_value(dev, "ID_REVISION");
if (val != NULL) { if (val) {
*version = (Uint16)SDL_strtol(val, NULL, 16); *version = (Uint16)SDL_strtol(val, NULL, 16);
} }
} }
@ -271,11 +271,11 @@ SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16
void SDL_UDEV_UnloadLibrary(void) void SDL_UDEV_UnloadLibrary(void)
{ {
if (_this == NULL) { if (!_this) {
return; return;
} }
if (_this->udev_handle != NULL) { if (_this->udev_handle) {
SDL_UnloadObject(_this->udev_handle); SDL_UnloadObject(_this->udev_handle);
_this->udev_handle = NULL; _this->udev_handle = NULL;
} }
@ -285,7 +285,7 @@ int SDL_UDEV_LoadLibrary(void)
{ {
int retval = 0, i; int retval = 0, i;
if (_this == NULL) { if (!_this) {
return SDL_SetError("UDEV not initialized"); return SDL_SetError("UDEV not initialized");
} }
@ -296,9 +296,9 @@ int SDL_UDEV_LoadLibrary(void)
#ifdef SDL_UDEV_DYNAMIC #ifdef SDL_UDEV_DYNAMIC
/* Check for the build environment's libudev first */ /* Check for the build environment's libudev first */
if (_this->udev_handle == NULL) { if (!_this->udev_handle) {
_this->udev_handle = SDL_LoadObject(SDL_UDEV_DYNAMIC); _this->udev_handle = SDL_LoadObject(SDL_UDEV_DYNAMIC);
if (_this->udev_handle != NULL) { if (_this->udev_handle) {
retval = SDL_UDEV_load_syms(); retval = SDL_UDEV_load_syms();
if (retval < 0) { if (retval < 0) {
SDL_UDEV_UnloadLibrary(); SDL_UDEV_UnloadLibrary();
@ -307,10 +307,10 @@ int SDL_UDEV_LoadLibrary(void)
} }
#endif #endif
if (_this->udev_handle == NULL) { if (!_this->udev_handle) {
for (i = 0; i < SDL_arraysize(SDL_UDEV_LIBS); i++) { for (i = 0; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
_this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]); _this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]);
if (_this->udev_handle != NULL) { if (_this->udev_handle) {
retval = SDL_UDEV_load_syms(); retval = SDL_UDEV_load_syms();
if (retval < 0) { if (retval < 0) {
SDL_UDEV_UnloadLibrary(); SDL_UDEV_UnloadLibrary();
@ -320,7 +320,7 @@ int SDL_UDEV_LoadLibrary(void)
} }
} }
if (_this->udev_handle == NULL) { if (!_this->udev_handle) {
retval = -1; retval = -1;
/* Don't call SDL_SetError(): SDL_LoadObject already did. */ /* Don't call SDL_SetError(): SDL_LoadObject already did. */
} }
@ -339,7 +339,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
SDL_memset(bitmask, 0, bitmask_len * sizeof(*bitmask)); SDL_memset(bitmask, 0, bitmask_len * sizeof(*bitmask));
value = _this->syms.udev_device_get_sysattr_value(pdev, attr); value = _this->syms.udev_device_get_sysattr_value(pdev, attr);
if (value == NULL) { if (!value) {
return; return;
} }
@ -374,7 +374,7 @@ static int guess_device_class(struct udev_device *dev)
while (pdev && !_this->syms.udev_device_get_sysattr_value(pdev, "capabilities/ev")) { while (pdev && !_this->syms.udev_device_get_sysattr_value(pdev, "capabilities/ev")) {
pdev = _this->syms.udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL); pdev = _this->syms.udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL);
} }
if (pdev == NULL) { if (!pdev) {
return 0; return 0;
} }
@ -400,7 +400,7 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
SDL_UDEV_CallbackList *item; SDL_UDEV_CallbackList *item;
path = _this->syms.udev_device_get_devnode(dev); path = _this->syms.udev_device_get_devnode(dev);
if (path == NULL) { if (!path) {
return; return;
} }
@ -411,23 +411,23 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
/* udev rules reference: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c */ /* udev rules reference: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c */
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK"); val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK");
if (val != NULL && SDL_strcmp(val, "1") == 0) { if (val && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_JOYSTICK; devclass |= SDL_UDEV_DEVICE_JOYSTICK;
} }
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_ACCELEROMETER"); val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_ACCELEROMETER");
if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE) && if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE) &&
val != NULL && SDL_strcmp(val, "1") == 0) { val && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_JOYSTICK; devclass |= SDL_UDEV_DEVICE_JOYSTICK;
} }
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_MOUSE"); val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
if (val != NULL && SDL_strcmp(val, "1") == 0) { if (val && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_MOUSE; devclass |= SDL_UDEV_DEVICE_MOUSE;
} }
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN"); val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN");
if (val != NULL && SDL_strcmp(val, "1") == 0) { if (val && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN; devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
} }
@ -438,19 +438,19 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
Ref: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c#n183 Ref: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c#n183
*/ */
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_KEY"); val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_KEY");
if (val != NULL && SDL_strcmp(val, "1") == 0) { if (val && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_HAS_KEYS; devclass |= SDL_UDEV_DEVICE_HAS_KEYS;
} }
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD"); val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD");
if (val != NULL && SDL_strcmp(val, "1") == 0) { if (val && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_KEYBOARD; devclass |= SDL_UDEV_DEVICE_KEYBOARD;
} }
if (devclass == 0) { if (devclass == 0) {
/* Fall back to old style input classes */ /* Fall back to old style input classes */
val = _this->syms.udev_device_get_property_value(dev, "ID_CLASS"); val = _this->syms.udev_device_get_property_value(dev, "ID_CLASS");
if (val != NULL) { if (val) {
if (SDL_strcmp(val, "joystick") == 0) { if (SDL_strcmp(val, "joystick") == 0) {
devclass = SDL_UDEV_DEVICE_JOYSTICK; devclass = SDL_UDEV_DEVICE_JOYSTICK;
} else if (SDL_strcmp(val, "mouse") == 0) { } else if (SDL_strcmp(val, "mouse") == 0) {
@ -470,7 +470,7 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
} }
/* Process callbacks */ /* Process callbacks */
for (item = _this->first; item != NULL; item = item->next) { for (item = _this->first; item; item = item->next) {
item->callback(type, devclass, path); item->callback(type, devclass, path);
} }
} }
@ -480,13 +480,13 @@ void SDL_UDEV_Poll(void)
struct udev_device *dev = NULL; struct udev_device *dev = NULL;
const char *action = NULL; const char *action = NULL;
if (_this == NULL) { if (!_this) {
return; return;
} }
while (SDL_UDEV_hotplug_update_available()) { while (SDL_UDEV_hotplug_update_available()) {
dev = _this->syms.udev_monitor_receive_device(_this->udev_mon); dev = _this->syms.udev_monitor_receive_device(_this->udev_mon);
if (dev == NULL) { if (!dev) {
break; break;
} }
action = _this->syms.udev_device_get_action(dev); action = _this->syms.udev_device_get_action(dev);
@ -507,13 +507,13 @@ int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
{ {
SDL_UDEV_CallbackList *item; SDL_UDEV_CallbackList *item;
item = (SDL_UDEV_CallbackList *)SDL_calloc(1, sizeof(SDL_UDEV_CallbackList)); item = (SDL_UDEV_CallbackList *)SDL_calloc(1, sizeof(SDL_UDEV_CallbackList));
if (item == NULL) { if (!item) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
item->callback = cb; item->callback = cb;
if (_this->last == NULL) { if (!_this->last) {
_this->first = _this->last = item; _this->first = _this->last = item;
} else { } else {
_this->last->next = item; _this->last->next = item;
@ -528,14 +528,14 @@ void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
SDL_UDEV_CallbackList *item; SDL_UDEV_CallbackList *item;
SDL_UDEV_CallbackList *prev = NULL; SDL_UDEV_CallbackList *prev = NULL;
if (_this == NULL) { if (!_this) {
return; return;
} }
for (item = _this->first; item != NULL; item = item->next) { for (item = _this->first; item; item = item->next) {
/* found it, remove it. */ /* found it, remove it. */
if (item->callback == cb) { if (item->callback == cb) {
if (prev != NULL) { if (prev) {
prev->next = item->next; prev->next = item->next;
} else { } else {
SDL_assert(_this->first == item); SDL_assert(_this->first == item);

View File

@ -57,7 +57,7 @@ SDL_RunApp(int argc_, char* argv_[], SDL_main_func mainFunction, void * reserved
newHeap = User::ChunkHeap(NULL, heapSize, heapSize, KMinHeapGrowBy); newHeap = User::ChunkHeap(NULL, heapSize, heapSize, KMinHeapGrowBy);
if (newHeap == NULL) { if (!newHeap) {
ret = 3; ret = 3;
goto cleanup; goto cleanup;
} else { } else {

View File

@ -419,7 +419,7 @@ static SDL_WSCONS_input_data *SDL_WSCONS_Init_Keyboard(const char *dev)
#endif #endif
SDL_WSCONS_input_data *input = (SDL_WSCONS_input_data *)SDL_calloc(1, sizeof(SDL_WSCONS_input_data)); SDL_WSCONS_input_data *input = (SDL_WSCONS_input_data *)SDL_calloc(1, sizeof(SDL_WSCONS_input_data));
if (input == NULL) { if (!input) {
return input; return input;
} }
input->fd = open(dev, O_RDWR | O_NONBLOCK | O_CLOEXEC); input->fd = open(dev, O_RDWR | O_NONBLOCK | O_CLOEXEC);
@ -429,7 +429,7 @@ static SDL_WSCONS_input_data *SDL_WSCONS_Init_Keyboard(const char *dev)
return NULL; return NULL;
} }
input->keymap.map = SDL_calloc(sizeof(struct wscons_keymap), KS_NUMKEYCODES); input->keymap.map = SDL_calloc(sizeof(struct wscons_keymap), KS_NUMKEYCODES);
if (input->keymap.map == NULL) { if (!input->keymap.map) {
SDL_free(input); SDL_free(input);
return NULL; return NULL;
} }
@ -579,7 +579,7 @@ static void updateKeyboard(SDL_WSCONS_input_data *input)
keysym_t *group; keysym_t *group;
keysym_t ksym, result; keysym_t ksym, result;
if (input == NULL) { if (!input) {
return; return;
} }
if ((n = read(input->fd, events, sizeof(events))) > 0) { if ((n = read(input->fd, events, sizeof(events))) > 0) {
@ -923,7 +923,7 @@ void SDL_WSCONS_PumpEvents()
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
updateKeyboard(inputs[i]); updateKeyboard(inputs[i]);
} }
if (mouseInputData != NULL) { if (mouseInputData) {
updateMouse(mouseInputData); updateMouse(mouseInputData);
} }
} }

View File

@ -41,7 +41,7 @@ SDL_WSCONS_mouse_input_data *SDL_WSCONS_Init_Mouse()
#endif #endif
SDL_WSCONS_mouse_input_data *mouseInputData = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data)); SDL_WSCONS_mouse_input_data *mouseInputData = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data));
if (mouseInputData == NULL) { if (!mouseInputData) {
return NULL; return NULL;
} }
mouseInputData->fd = open("/dev/wsmouse", O_RDWR | O_NONBLOCK | O_CLOEXEC); mouseInputData->fd = open("/dev/wsmouse", O_RDWR | O_NONBLOCK | O_CLOEXEC);
@ -125,7 +125,7 @@ void updateMouse(SDL_WSCONS_mouse_input_data *inputData)
void SDL_WSCONS_Quit_Mouse(SDL_WSCONS_mouse_input_data *inputData) void SDL_WSCONS_Quit_Mouse(SDL_WSCONS_mouse_input_data *inputData)
{ {
if (inputData == NULL) { if (!inputData) {
return; return;
} }
close(inputData->fd); close(inputData->fd);

View File

@ -58,9 +58,9 @@ int WIN_LoadHIDDLL(void)
SDL_HidP_GetValueCaps = (HidP_GetValueCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetValueCaps"); SDL_HidP_GetValueCaps = (HidP_GetValueCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetValueCaps");
SDL_HidP_MaxDataListLength = (HidP_MaxDataListLength_t)GetProcAddress(s_pHIDDLL, "HidP_MaxDataListLength"); SDL_HidP_MaxDataListLength = (HidP_MaxDataListLength_t)GetProcAddress(s_pHIDDLL, "HidP_MaxDataListLength");
SDL_HidP_GetData = (HidP_GetData_t)GetProcAddress(s_pHIDDLL, "HidP_GetData"); SDL_HidP_GetData = (HidP_GetData_t)GetProcAddress(s_pHIDDLL, "HidP_GetData");
if (SDL_HidD_GetManufacturerString == NULL || SDL_HidD_GetProductString == NULL || if (!SDL_HidD_GetManufacturerString || !SDL_HidD_GetProductString ||
SDL_HidP_GetCaps == NULL || SDL_HidP_GetButtonCaps == NULL || !SDL_HidP_GetCaps || !SDL_HidP_GetButtonCaps ||
SDL_HidP_GetValueCaps == NULL || SDL_HidP_MaxDataListLength == NULL || SDL_HidP_GetData == NULL) { !SDL_HidP_GetValueCaps || !SDL_HidP_MaxDataListLength || !SDL_HidP_GetData) {
WIN_UnloadHIDDLL(); WIN_UnloadHIDDLL();
return -1; return -1;
} }

View File

@ -342,8 +342,8 @@ int SDL_IMMDevice_Get(SDL_AudioDevice *device, IMMDevice **immdevice, SDL_bool i
{ {
const Uint64 timeout = SDL_GetTicks() + 8000; /* intel's audio drivers can fail for up to EIGHT SECONDS after a device is connected or we wake from sleep. */ const Uint64 timeout = SDL_GetTicks() + 8000; /* intel's audio drivers can fail for up to EIGHT SECONDS after a device is connected or we wake from sleep. */
SDL_assert(device != NULL); SDL_assert(device);
SDL_assert(immdevice != NULL); SDL_assert(immdevice);
LPCWSTR devid = SDL_IMMDevice_GetDevID(device); LPCWSTR devid = SDL_IMMDevice_GetDevID(device);
SDL_assert(devid != NULL); SDL_assert(devid != NULL);

View File

@ -283,7 +283,7 @@ char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
} }
strw = (WCHAR *)SDL_malloc(len + sizeof(WCHAR)); strw = (WCHAR *)SDL_malloc(len + sizeof(WCHAR));
if (strw == NULL) { if (!strw) {
RegCloseKey(hkey); RegCloseKey(hkey);
return WIN_StringToUTF8(name); /* oh well. */ return WIN_StringToUTF8(name); /* oh well. */
} }
@ -388,7 +388,7 @@ DECLSPEC int MINGW32_FORCEALIGN SDL_RunApp(int _argc, char* _argv[], SDL_main_fu
(void)_argc; (void)_argv; (void)reserved; (void)_argc; (void)_argv; (void)reserved;
argvw = CommandLineToArgvW(GetCommandLineW(), &argc); argvw = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argvw == NULL) { if (!argvw) {
return OutOfMemory(); return OutOfMemory();
} }
@ -399,13 +399,13 @@ DECLSPEC int MINGW32_FORCEALIGN SDL_RunApp(int _argc, char* _argv[], SDL_main_fu
/* Parse it into argv and argc */ /* Parse it into argv and argc */
argv = (char **)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (argc + 1) * sizeof(*argv)); argv = (char **)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (argc + 1) * sizeof(*argv));
if (argv == NULL) { if (!argv) {
return OutOfMemory(); return OutOfMemory();
} }
for (i = 0; i < argc; ++i) { for (i = 0; i < argc; ++i) {
DWORD len; DWORD len;
char *arg = WIN_StringToUTF8W(argvw[i]); char *arg = WIN_StringToUTF8W(argvw[i]);
if (arg == NULL) { if (!arg) {
return OutOfMemory(); return OutOfMemory();
} }
len = (DWORD)SDL_strlen(arg); len = (DWORD)SDL_strlen(arg);

View File

@ -106,13 +106,13 @@ int WIN_LoadXInputDLL(void)
/* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */ /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */
SDL_XInputGetState = (XInputGetState_t)GetProcAddress(s_pXInputDLL, (LPCSTR)100); SDL_XInputGetState = (XInputGetState_t)GetProcAddress(s_pXInputDLL, (LPCSTR)100);
if (SDL_XInputGetState == NULL) { if (!SDL_XInputGetState) {
SDL_XInputGetState = (XInputGetState_t)GetProcAddress(s_pXInputDLL, "XInputGetState"); SDL_XInputGetState = (XInputGetState_t)GetProcAddress(s_pXInputDLL, "XInputGetState");
} }
SDL_XInputSetState = (XInputSetState_t)GetProcAddress(s_pXInputDLL, "XInputSetState"); SDL_XInputSetState = (XInputSetState_t)GetProcAddress(s_pXInputDLL, "XInputSetState");
SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress(s_pXInputDLL, "XInputGetCapabilities"); SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress(s_pXInputDLL, "XInputGetCapabilities");
SDL_XInputGetBatteryInformation = (XInputGetBatteryInformation_t)GetProcAddress(s_pXInputDLL, "XInputGetBatteryInformation"); SDL_XInputGetBatteryInformation = (XInputGetBatteryInformation_t)GetProcAddress(s_pXInputDLL, "XInputGetBatteryInformation");
if (SDL_XInputGetState == NULL || SDL_XInputSetState == NULL || SDL_XInputGetCapabilities == NULL) { if (!SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities) {
WIN_UnloadXInputDLL(); WIN_UnloadXInputDLL();
return -1; return -1;
} }

View File

@ -343,7 +343,7 @@ void SDL_WinRTApp::Run()
// representation of command line arguments. // representation of command line arguments.
int argc = 1; int argc = 1;
char **argv = (char **)SDL_malloc(2 * sizeof(*argv)); char **argv = (char **)SDL_malloc(2 * sizeof(*argv));
if (argv == NULL) { if (!argv) {
return; return;
} }
argv[0] = SDL_strdup("WinRTApp"); argv[0] = SDL_strdup("WinRTApp");

View File

@ -418,7 +418,7 @@ static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
void *retval = NULL; void *retval = NULL;
if (lib) { if (lib) {
retval = (void *) GetProcAddress(lib, sym); retval = (void *) GetProcAddress(lib, sym);
if (retval == NULL) { if (!retval) {
FreeLibrary(lib); FreeLibrary(lib);
} }
} }
@ -431,9 +431,9 @@ static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
{ {
void *lib = dlopen(fname, RTLD_NOW | RTLD_LOCAL); void *lib = dlopen(fname, RTLD_NOW | RTLD_LOCAL);
void *retval = NULL; void *retval = NULL;
if (lib != NULL) { if (lib) {
retval = dlsym(lib, sym); retval = dlsym(lib, sym);
if (retval == NULL) { if (!retval) {
dlclose(lib); dlclose(lib);
} }
} }

View File

@ -28,7 +28,7 @@ int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent,
{ {
int posted; int posted;
if (display == NULL || display->id == 0) { if (!display || display->id == 0) {
return 0; return 0;
} }
switch (displayevent) { switch (displayevent) {

View File

@ -778,7 +778,7 @@ int SDL_SetKeyboardFocus(SDL_Window *window)
} }
} }
if (keyboard->focus && window == NULL) { if (keyboard->focus && !window) {
/* We won't get anymore keyboard messages, so reset keyboard state */ /* We won't get anymore keyboard messages, so reset keyboard state */
SDL_ResetKeyboard(); SDL_ResetKeyboard();
} }
@ -787,7 +787,7 @@ int SDL_SetKeyboardFocus(SDL_Window *window)
if (keyboard->focus && keyboard->focus != window) { if (keyboard->focus && keyboard->focus != window) {
/* new window shouldn't think it has mouse captured. */ /* new window shouldn't think it has mouse captured. */
SDL_assert(window == NULL || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE)); SDL_assert(!window || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE));
/* old window must lose an existing mouse capture. */ /* old window must lose an existing mouse capture. */
if (keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE) { if (keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE) {
@ -1199,7 +1199,7 @@ const char *SDL_GetScancodeName(SDL_Scancode scancode)
} }
name = SDL_scancode_names[scancode]; name = SDL_scancode_names[scancode];
if (name != NULL) { if (name) {
return name; return name;
} }
@ -1210,7 +1210,7 @@ SDL_Scancode SDL_GetScancodeFromName(const char *name)
{ {
int i; int i;
if (name == NULL || !*name) { if (!name || !*name) {
SDL_InvalidParamError("name"); SDL_InvalidParamError("name");
return SDL_SCANCODE_UNKNOWN; return SDL_SCANCODE_UNKNOWN;
} }
@ -1270,7 +1270,7 @@ SDL_Keycode SDL_GetKeyFromName(const char *name)
SDL_Keycode key; SDL_Keycode key;
/* Check input */ /* Check input */
if (name == NULL) { if (!name) {
return SDLK_UNKNOWN; return SDLK_UNKNOWN;
} }

View File

@ -476,7 +476,7 @@ int SDL_SetMouseSystemScale(int num_values, const float *values)
} }
v = (float *)SDL_realloc(mouse->system_scale_values, num_values * sizeof(*values)); v = (float *)SDL_realloc(mouse->system_scale_values, num_values * sizeof(*values));
if (v == NULL) { if (!v) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memcpy(v, values, num_values * sizeof(*values)); SDL_memcpy(v, values, num_values * sizeof(*values));
@ -704,7 +704,7 @@ static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
if (button >= mouse->num_clickstates) { if (button >= mouse->num_clickstates) {
int i, count = button + 1; int i, count = button + 1;
SDL_MouseClickState *clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate)); SDL_MouseClickState *clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate));
if (clickstate == NULL) { if (!clickstate) {
return NULL; return NULL;
} }
mouse->clickstate = clickstate; mouse->clickstate = clickstate;
@ -726,7 +726,7 @@ static int SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_
SDL_MouseInputSource *source; SDL_MouseInputSource *source;
source = GetMouseInputSource(mouse, mouseID); source = GetMouseInputSource(mouse, mouseID);
if (source == NULL) { if (!source) {
return 0; return 0;
} }
buttonstate = source->buttonstate; buttonstate = source->buttonstate;
@ -982,10 +982,10 @@ Uint32 SDL_GetGlobalMouseState(float *x, float *y)
float tmpx, tmpy; float tmpx, tmpy;
/* make sure these are never NULL for the backend implementations... */ /* make sure these are never NULL for the backend implementations... */
if (x == NULL) { if (!x) {
x = &tmpx; x = &tmpx;
} }
if (y == NULL) { if (!y) {
y = &tmpy; y = &tmpy;
} }
@ -1001,11 +1001,11 @@ void SDL_PerformWarpMouseInWindow(SDL_Window *window, float x, float y, SDL_bool
{ {
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
if (window == NULL) { if (!window) {
window = mouse->focus; window = mouse->focus;
} }
if (window == NULL) { if (!window) {
return; return;
} }
@ -1231,7 +1231,7 @@ SDL_Cursor *SDL_CreateCursor(const Uint8 *data, const Uint8 *mask, int w, int h,
/* Create the surface from a bitmap */ /* Create the surface from a bitmap */
surface = SDL_CreateSurface(w, h, SDL_PIXELFORMAT_ARGB8888); surface = SDL_CreateSurface(w, h, SDL_PIXELFORMAT_ARGB8888);
if (surface == NULL) { if (!surface) {
return NULL; return NULL;
} }
for (y = 0; y < h; ++y) { for (y = 0; y < h; ++y) {
@ -1264,7 +1264,7 @@ SDL_Cursor *SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
SDL_Surface *temp = NULL; SDL_Surface *temp = NULL;
SDL_Cursor *cursor; SDL_Cursor *cursor;
if (surface == NULL) { if (!surface) {
SDL_InvalidParamError("surface"); SDL_InvalidParamError("surface");
return NULL; return NULL;
} }
@ -1278,7 +1278,7 @@ SDL_Cursor *SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) { if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) {
temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888); temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888);
if (temp == NULL) { if (!temp) {
return NULL; return NULL;
} }
surface = temp; surface = temp;
@ -1344,7 +1344,7 @@ int SDL_SetCursor(SDL_Cursor *cursor)
break; break;
} }
} }
if (found == NULL) { if (!found) {
return SDL_SetError("Cursor not associated with the current mouse"); return SDL_SetError("Cursor not associated with the current mouse");
} }
} }
@ -1373,7 +1373,7 @@ SDL_Cursor *SDL_GetCursor(void)
{ {
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
if (mouse == NULL) { if (!mouse) {
return NULL; return NULL;
} }
return mouse->cur_cursor; return mouse->cur_cursor;
@ -1383,7 +1383,7 @@ SDL_Cursor *SDL_GetDefaultCursor(void)
{ {
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
if (mouse == NULL) { if (!mouse) {
return NULL; return NULL;
} }
return mouse->def_cursor; return mouse->def_cursor;
@ -1394,7 +1394,7 @@ void SDL_DestroyCursor(SDL_Cursor *cursor)
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
SDL_Cursor *curr, *prev; SDL_Cursor *curr, *prev;
if (cursor == NULL) { if (!cursor) {
return; return;
} }

View File

@ -137,7 +137,7 @@ int SDL_GetNumTouchFingers(SDL_TouchID touchID)
SDL_Finger *SDL_GetTouchFinger(SDL_TouchID touchID, int index) SDL_Finger *SDL_GetTouchFinger(SDL_TouchID touchID, int index)
{ {
SDL_Touch *touch = SDL_GetTouch(touchID); SDL_Touch *touch = SDL_GetTouch(touchID);
if (touch == NULL) { if (!touch) {
return NULL; return NULL;
} }
if (index < 0 || index >= touch->num_fingers) { if (index < 0 || index >= touch->num_fingers) {
@ -160,7 +160,7 @@ int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name
/* Add the touch to the list of touch */ /* Add the touch to the list of touch */
touchDevices = (SDL_Touch **)SDL_realloc(SDL_touchDevices, touchDevices = (SDL_Touch **)SDL_realloc(SDL_touchDevices,
(SDL_num_touch + 1) * sizeof(*touchDevices)); (SDL_num_touch + 1) * sizeof(*touchDevices));
if (touchDevices == NULL) { if (!touchDevices) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -193,7 +193,7 @@ static int SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float
if (touch->num_fingers == touch->max_fingers) { if (touch->num_fingers == touch->max_fingers) {
SDL_Finger **new_fingers; SDL_Finger **new_fingers;
new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers + 1) * sizeof(*touch->fingers)); new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers + 1) * sizeof(*touch->fingers));
if (new_fingers == NULL) { if (!new_fingers) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
touch->fingers = new_fingers; touch->fingers = new_fingers;
@ -235,7 +235,7 @@ int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_W
SDL_Mouse *mouse; SDL_Mouse *mouse;
SDL_Touch *touch = SDL_GetTouch(id); SDL_Touch *touch = SDL_GetTouch(id);
if (touch == NULL) { if (!touch) {
return -1; return -1;
} }
@ -329,7 +329,7 @@ int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_W
posted = (SDL_PushEvent(&event) > 0); posted = (SDL_PushEvent(&event) > 0);
} }
} else { } else {
if (finger == NULL) { if (!finger) {
/* This finger is already up */ /* This finger is already up */
return 0; return 0;
} }
@ -366,7 +366,7 @@ int SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid,
float xrel, yrel, prel; float xrel, yrel, prel;
touch = SDL_GetTouch(id); touch = SDL_GetTouch(id);
if (touch == NULL) { if (!touch) {
return -1; return -1;
} }
@ -409,7 +409,7 @@ int SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid,
} }
finger = SDL_GetFinger(touch, fingerid); finger = SDL_GetFinger(touch, fingerid);
if (finger == NULL) { if (!finger) {
return SDL_SendTouch(timestamp, id, fingerid, window, SDL_TRUE, x, y, pressure); return SDL_SendTouch(timestamp, id, fingerid, window, SDL_TRUE, x, y, pressure);
} }
@ -461,7 +461,7 @@ void SDL_DelTouch(SDL_TouchID id)
index = SDL_GetTouchIndex(id); index = SDL_GetTouchIndex(id);
touch = SDL_GetTouch(id); touch = SDL_GetTouch(id);
if (touch == NULL) { if (!touch) {
return; return;
} }

View File

@ -43,7 +43,7 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
{ {
int posted; int posted;
if (window == NULL) { if (!window) {
return 0; return 0;
} }
if (window->is_destroying && windowevent != SDL_EVENT_WINDOW_DESTROYED) { if (window->is_destroying && windowevent != SDL_EVENT_WINDOW_DESTROYED) {
@ -222,11 +222,11 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
break; break;
} }
if (windowevent == SDL_EVENT_WINDOW_CLOSE_REQUESTED && window->parent == NULL) { if (windowevent == SDL_EVENT_WINDOW_CLOSE_REQUESTED && !window->parent) {
int toplevel_count = 0; int toplevel_count = 0;
SDL_Window *n; SDL_Window *n;
for (n = SDL_GetVideoDevice()->windows; n != NULL; n = n->next) { for (n = SDL_GetVideoDevice()->windows; n; n = n->next) {
if (n->parent == NULL) { if (!n->parent) {
++toplevel_count; ++toplevel_count;
} }
} }

View File

@ -389,7 +389,7 @@ static SDL_RWops *SDL_RWFromFP(void *fp, SDL_bool autoclose)
SDL_RWops *rwops = NULL; SDL_RWops *rwops = NULL;
rwops = SDL_CreateRW(); rwops = SDL_CreateRW();
if (rwops != NULL) { if (rwops) {
rwops->seek = stdio_seek; rwops->seek = stdio_seek;
rwops->read = stdio_read; rwops->read = stdio_read;
rwops->write = stdio_write; rwops->write = stdio_write;
@ -462,7 +462,7 @@ static size_t SDLCALL mem_write(SDL_RWops *context, const void *ptr, size_t size
SDL_RWops *SDL_RWFromFile(const char *file, const char *mode) SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
{ {
SDL_RWops *rwops = NULL; SDL_RWops *rwops = NULL;
if (file == NULL || !*file || mode == NULL || !*mode) { if (!file || !*file || !mode || !*mode) {
SDL_SetError("SDL_RWFromFile(): No file or no mode specified"); SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
return NULL; return NULL;
} }
@ -495,7 +495,7 @@ SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
/* Try to open the file from the asset system */ /* Try to open the file from the asset system */
rwops = SDL_CreateRW(); rwops = SDL_CreateRW();
if (rwops == NULL) { if (!rwops) {
return NULL; /* SDL_SetError already setup by SDL_CreateRW() */ return NULL; /* SDL_SetError already setup by SDL_CreateRW() */
} }
@ -512,7 +512,7 @@ SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
#elif defined(__WIN32__) || defined(__GDK__) || defined(__WINRT__) #elif defined(__WIN32__) || defined(__GDK__) || defined(__WINRT__)
rwops = SDL_CreateRW(); rwops = SDL_CreateRW();
if (rwops == NULL) { if (!rwops) {
return NULL; /* SDL_SetError already setup by SDL_CreateRW() */ return NULL; /* SDL_SetError already setup by SDL_CreateRW() */
} }
@ -538,7 +538,7 @@ SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
#else #else
FILE *fp = fopen(file, mode); FILE *fp = fopen(file, mode);
#endif #endif
if (fp == NULL) { if (!fp) {
SDL_SetError("Couldn't open %s", file); SDL_SetError("Couldn't open %s", file);
} else { } else {
rwops = SDL_RWFromFP(fp, SDL_TRUE); rwops = SDL_RWFromFP(fp, SDL_TRUE);
@ -555,7 +555,7 @@ SDL_RWops *SDL_RWFromMem(void *mem, size_t size)
{ {
SDL_RWops *rwops = NULL; SDL_RWops *rwops = NULL;
if (mem == NULL) { if (!mem) {
SDL_InvalidParamError("mem"); SDL_InvalidParamError("mem");
return NULL; return NULL;
} }
@ -565,7 +565,7 @@ SDL_RWops *SDL_RWFromMem(void *mem, size_t size)
} }
rwops = SDL_CreateRW(); rwops = SDL_CreateRW();
if (rwops != NULL) { if (rwops) {
rwops->size = mem_size; rwops->size = mem_size;
rwops->seek = mem_seek; rwops->seek = mem_seek;
rwops->read = mem_read; rwops->read = mem_read;
@ -582,7 +582,7 @@ SDL_RWops *SDL_RWFromConstMem(const void *mem, size_t size)
{ {
SDL_RWops *rwops = NULL; SDL_RWops *rwops = NULL;
if (mem == NULL) { if (!mem) {
SDL_InvalidParamError("mem"); SDL_InvalidParamError("mem");
return NULL; return NULL;
} }
@ -592,7 +592,7 @@ SDL_RWops *SDL_RWFromConstMem(const void *mem, size_t size)
} }
rwops = SDL_CreateRW(); rwops = SDL_CreateRW();
if (rwops != NULL) { if (rwops) {
rwops->size = mem_size; rwops->size = mem_size;
rwops->seek = mem_seek; rwops->seek = mem_seek;
rwops->read = mem_read; rwops->read = mem_read;
@ -609,7 +609,7 @@ SDL_RWops *SDL_CreateRW(void)
SDL_RWops *context; SDL_RWops *context;
context = (SDL_RWops *)SDL_calloc(1, sizeof(*context)); context = (SDL_RWops *)SDL_calloc(1, sizeof(*context));
if (context == NULL) { if (!context) {
SDL_OutOfMemory(); SDL_OutOfMemory();
} else { } else {
context->type = SDL_RWOPS_UNKNOWN; context->type = SDL_RWOPS_UNKNOWN;
@ -632,7 +632,7 @@ void *SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc)
char *data = NULL, *newdata; char *data = NULL, *newdata;
SDL_bool loading_chunks = SDL_FALSE; SDL_bool loading_chunks = SDL_FALSE;
if (src == NULL) { if (!src) {
SDL_InvalidParamError("src"); SDL_InvalidParamError("src");
return NULL; return NULL;
} }
@ -662,7 +662,7 @@ void *SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc)
} else { } else {
newdata = SDL_realloc(data, (size_t)(size + 1)); newdata = SDL_realloc(data, (size_t)(size + 1));
} }
if (newdata == NULL) { if (!newdata) {
SDL_free(data); SDL_free(data);
data = NULL; data = NULL;
SDL_OutOfMemory(); SDL_OutOfMemory();

View File

@ -65,7 +65,7 @@ static FILE *TryOpenFile(const char *file, const char *mode)
FILE *fp = NULL; FILE *fp = NULL;
fp = TryOpenInRomfs(file, mode); fp = TryOpenInRomfs(file, mode);
if (fp == NULL) { if (!fp) {
fp = fopen(file, mode); fp = fopen(file, mode);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -55,7 +55,7 @@ static int ValidHaptic(SDL_Haptic *haptic)
SDL_Haptic *hapticlist; SDL_Haptic *hapticlist;
valid = 0; valid = 0;
if (haptic != NULL) { if (haptic) {
hapticlist = SDL_haptics; hapticlist = SDL_haptics;
while (hapticlist) { while (hapticlist) {
if (hapticlist == haptic) { if (hapticlist == haptic) {
@ -124,7 +124,7 @@ SDL_Haptic *SDL_HapticOpen(int device_index)
/* Create the haptic device */ /* Create the haptic device */
haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic)); haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic));
if (haptic == NULL) { if (!haptic) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
@ -296,7 +296,7 @@ SDL_Haptic *SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
/* Create the haptic device */ /* Create the haptic device */
haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic)); haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic));
if (haptic == NULL) { if (!haptic) {
SDL_OutOfMemory(); SDL_OutOfMemory();
SDL_UnlockJoysticks(); SDL_UnlockJoysticks();
return NULL; return NULL;
@ -609,7 +609,7 @@ int SDL_HapticSetGain(SDL_Haptic *haptic, int gain)
/* We use the envvar to get the maximum gain. */ /* We use the envvar to get the maximum gain. */
env = SDL_getenv("SDL_HAPTIC_GAIN_MAX"); env = SDL_getenv("SDL_HAPTIC_GAIN_MAX");
if (env != NULL) { if (env) {
max_gain = SDL_atoi(env); max_gain = SDL_atoi(env);
/* Check for sanity. */ /* Check for sanity. */

View File

@ -59,7 +59,7 @@ static SDL_hapticlist_item *HapticByOrder(int index)
return NULL; return NULL;
} }
while (index > 0) { while (index > 0) {
SDL_assert(item != NULL); SDL_assert(item);
--index; --index;
item = item->next; item = item->next;
} }
@ -69,7 +69,7 @@ static SDL_hapticlist_item *HapticByOrder(int index)
static SDL_hapticlist_item *HapticByDevId(int device_id) static SDL_hapticlist_item *HapticByDevId(int device_id)
{ {
SDL_hapticlist_item *item; SDL_hapticlist_item *item;
for (item = SDL_hapticlist; item != NULL; item = item->next) { for (item = SDL_hapticlist; item; item = item->next) {
if (device_id == item->device_id) { if (device_id == item->device_id) {
/*SDL_Log("=+=+=+=+=+= HapticByDevId id [%d]", device_id);*/ /*SDL_Log("=+=+=+=+=+= HapticByDevId id [%d]", device_id);*/
return item; return item;
@ -81,7 +81,7 @@ static SDL_hapticlist_item *HapticByDevId(int device_id)
const char *SDL_SYS_HapticName(int index) const char *SDL_SYS_HapticName(int index)
{ {
SDL_hapticlist_item *item = HapticByOrder(index); SDL_hapticlist_item *item = HapticByOrder(index);
if (item == NULL) { if (!item) {
SDL_SetError("No such device"); SDL_SetError("No such device");
return NULL; return NULL;
} }
@ -90,11 +90,11 @@ const char *SDL_SYS_HapticName(int index)
static SDL_hapticlist_item *OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *item) static SDL_hapticlist_item *OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *item)
{ {
if (item == NULL) { if (!item) {
SDL_SetError("No such device"); SDL_SetError("No such device");
return NULL; return NULL;
} }
if (item->haptic != NULL) { if (item->haptic) {
SDL_SetError("Haptic already opened"); SDL_SetError("Haptic already opened");
return NULL; return NULL;
} }
@ -106,7 +106,7 @@ static SDL_hapticlist_item *OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *
haptic->neffects = 1; haptic->neffects = 1;
haptic->nplaying = haptic->neffects; haptic->nplaying = haptic->neffects;
haptic->effects = (struct haptic_effect *)SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); haptic->effects = (struct haptic_effect *)SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
if (haptic->effects == NULL) { if (!haptic->effects) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
@ -138,7 +138,7 @@ int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
{ {
SDL_hapticlist_item *item; SDL_hapticlist_item *item;
item = HapticByDevId(((joystick_hwdata *)joystick->hwdata)->device_id); item = HapticByDevId(((joystick_hwdata *)joystick->hwdata)->device_id);
return (item != NULL) ? 1 : 0; return (item) ? 1 : 0;
} }
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
@ -246,18 +246,18 @@ int Android_AddHaptic(int device_id, const char *name)
{ {
SDL_hapticlist_item *item; SDL_hapticlist_item *item;
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item)); item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
if (item == NULL) { if (!item) {
return -1; return -1;
} }
item->device_id = device_id; item->device_id = device_id;
item->name = SDL_strdup(name); item->name = SDL_strdup(name);
if (item->name == NULL) { if (!item->name) {
SDL_free(item); SDL_free(item);
return -1; return -1;
} }
if (SDL_hapticlist_tail == NULL) { if (!SDL_hapticlist_tail) {
SDL_hapticlist = SDL_hapticlist_tail = item; SDL_hapticlist = SDL_hapticlist_tail = item;
} else { } else {
SDL_hapticlist_tail->next = item; SDL_hapticlist_tail->next = item;
@ -273,12 +273,12 @@ int Android_RemoveHaptic(int device_id)
SDL_hapticlist_item *item; SDL_hapticlist_item *item;
SDL_hapticlist_item *prev = NULL; SDL_hapticlist_item *prev = NULL;
for (item = SDL_hapticlist; item != NULL; item = item->next) { for (item = SDL_hapticlist; item; item = item->next) {
/* found it, remove it. */ /* found it, remove it. */
if (device_id == item->device_id) { if (device_id == item->device_id) {
const int retval = item->haptic ? item->haptic->index : -1; const int retval = item->haptic ? item->haptic->index : -1;
if (prev != NULL) { if (prev) {
prev->next = item->next; prev->next = item->next;
} else { } else {
SDL_assert(SDL_hapticlist == item); SDL_assert(SDL_hapticlist == item);

View File

@ -154,7 +154,7 @@ int SDL_SYS_HapticInit(void)
/* Get HID devices. */ /* Get HID devices. */
match = IOServiceMatching(kIOHIDDeviceKey); match = IOServiceMatching(kIOHIDDeviceKey);
if (match == NULL) { if (!match) {
return SDL_SetError("Haptic: Failed to get IOServiceMatching."); return SDL_SetError("Haptic: Failed to get IOServiceMatching.");
} }
@ -193,7 +193,7 @@ static SDL_hapticlist_item *HapticByDevIndex(int device_index)
} }
while (device_index > 0) { while (device_index > 0) {
SDL_assert(item != NULL); SDL_assert(item);
--device_index; --device_index;
item = item->next; item = item->next;
} }
@ -226,7 +226,7 @@ int MacHaptic_MaybeAddDevice(io_object_t device)
} }
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item)); item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
if (item == NULL) { if (!item) {
return SDL_SetError("Could not allocate haptic storage"); return SDL_SetError("Could not allocate haptic storage");
} }
@ -262,7 +262,7 @@ int MacHaptic_MaybeAddDevice(io_object_t device)
CFRelease(hidProperties); CFRelease(hidProperties);
} }
if (SDL_hapticlist_tail == NULL) { if (!SDL_hapticlist_tail) {
SDL_hapticlist = SDL_hapticlist_tail = item; SDL_hapticlist = SDL_hapticlist_tail = item;
} else { } else {
SDL_hapticlist_tail->next = item; SDL_hapticlist_tail->next = item;
@ -284,12 +284,12 @@ int MacHaptic_MaybeRemoveDevice(io_object_t device)
return -1; /* not initialized. ignore this. */ return -1; /* not initialized. ignore this. */
} }
for (item = SDL_hapticlist; item != NULL; item = item->next) { for (item = SDL_hapticlist; item; item = item->next) {
/* found it, remove it. */ /* found it, remove it. */
if (IOObjectIsEqualTo((io_object_t)item->dev, device)) { if (IOObjectIsEqualTo((io_object_t)item->dev, device)) {
const int retval = item->haptic ? item->haptic->index : -1; const int retval = item->haptic ? item->haptic->index : -1;
if (prev != NULL) { if (prev) {
prev->next = item->next; prev->next = item->next;
} else { } else {
SDL_assert(SDL_hapticlist == item); SDL_assert(SDL_hapticlist == item);
@ -475,7 +475,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
/* Allocate the hwdata */ /* Allocate the hwdata */
haptic->hwdata = (struct haptic_hwdata *) haptic->hwdata = (struct haptic_hwdata *)
SDL_malloc(sizeof(*haptic->hwdata)); SDL_malloc(sizeof(*haptic->hwdata));
if (haptic->hwdata == NULL) { if (!haptic->hwdata) {
SDL_OutOfMemory(); SDL_OutOfMemory();
goto creat_err; goto creat_err;
} }
@ -512,7 +512,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
/* Allocate effects memory. */ /* Allocate effects memory. */
haptic->effects = (struct haptic_effect *) haptic->effects = (struct haptic_effect *)
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
if (haptic->effects == NULL) { if (!haptic->effects) {
SDL_OutOfMemory(); SDL_OutOfMemory();
goto open_err; goto open_err;
} }
@ -526,7 +526,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
open_err: open_err:
FFReleaseDevice(haptic->hwdata->device); FFReleaseDevice(haptic->hwdata->device);
creat_err: creat_err:
if (haptic->hwdata != NULL) { if (haptic->hwdata) {
SDL_free(haptic->hwdata); SDL_free(haptic->hwdata);
haptic->hwdata = NULL; haptic->hwdata = NULL;
} }
@ -699,7 +699,7 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, SDL_HapticDirection *dir, int
/* Has axes. */ /* Has axes. */
rglDir = SDL_malloc(sizeof(LONG) * naxes); rglDir = SDL_malloc(sizeof(LONG) * naxes);
if (rglDir == NULL) { if (!rglDir) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(rglDir, 0, sizeof(LONG) * naxes); SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
@ -772,7 +772,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
/* Envelope. */ /* Envelope. */
envelope = SDL_malloc(sizeof(FFENVELOPE)); envelope = SDL_malloc(sizeof(FFENVELOPE));
if (envelope == NULL) { if (!envelope) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(envelope, 0, sizeof(FFENVELOPE)); SDL_memset(envelope, 0, sizeof(FFENVELOPE));
@ -787,7 +787,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
} }
if (dest->cAxes > 0) { if (dest->cAxes > 0) {
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes); axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
if (axes == NULL) { if (!axes) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */ axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
@ -805,7 +805,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
case SDL_HAPTIC_CONSTANT: case SDL_HAPTIC_CONSTANT:
hap_constant = &src->constant; hap_constant = &src->constant;
constant = SDL_malloc(sizeof(FFCONSTANTFORCE)); constant = SDL_malloc(sizeof(FFCONSTANTFORCE));
if (constant == NULL) { if (!constant) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE)); SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE));
@ -847,7 +847,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
case SDL_HAPTIC_SAWTOOTHDOWN: case SDL_HAPTIC_SAWTOOTHDOWN:
hap_periodic = &src->periodic; hap_periodic = &src->periodic;
periodic = SDL_malloc(sizeof(FFPERIODIC)); periodic = SDL_malloc(sizeof(FFPERIODIC));
if (periodic == NULL) { if (!periodic) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(periodic, 0, sizeof(FFPERIODIC)); SDL_memset(periodic, 0, sizeof(FFPERIODIC));
@ -892,7 +892,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
hap_condition = &src->condition; hap_condition = &src->condition;
if (dest->cAxes > 0) { if (dest->cAxes > 0) {
condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes); condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
if (condition == NULL) { if (!condition) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(condition, 0, sizeof(FFCONDITION)); SDL_memset(condition, 0, sizeof(FFCONDITION));
@ -935,7 +935,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
case SDL_HAPTIC_RAMP: case SDL_HAPTIC_RAMP:
hap_ramp = &src->ramp; hap_ramp = &src->ramp;
ramp = SDL_malloc(sizeof(FFRAMPFORCE)); ramp = SDL_malloc(sizeof(FFRAMPFORCE));
if (ramp == NULL) { if (!ramp) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(ramp, 0, sizeof(FFRAMPFORCE)); SDL_memset(ramp, 0, sizeof(FFRAMPFORCE));
@ -973,7 +973,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
case SDL_HAPTIC_CUSTOM: case SDL_HAPTIC_CUSTOM:
hap_custom = &src->custom; hap_custom = &src->custom;
custom = SDL_malloc(sizeof(FFCUSTOMFORCE)); custom = SDL_malloc(sizeof(FFCUSTOMFORCE));
if (custom == NULL) { if (!custom) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE)); SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE));
@ -1033,7 +1033,7 @@ static void SDL_SYS_HapticFreeFFEFFECT(FFEFFECT *effect, int type)
effect->lpEnvelope = NULL; effect->lpEnvelope = NULL;
SDL_free(effect->rgdwAxes); SDL_free(effect->rgdwAxes);
effect->rgdwAxes = NULL; effect->rgdwAxes = NULL;
if (effect->lpvTypeSpecificParams != NULL) { if (effect->lpvTypeSpecificParams) {
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */ if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
custom = (FFCUSTOMFORCE *)effect->lpvTypeSpecificParams; custom = (FFCUSTOMFORCE *)effect->lpvTypeSpecificParams;
SDL_free(custom->rglForceData); SDL_free(custom->rglForceData);
@ -1108,14 +1108,14 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
/* Alloc the effect. */ /* Alloc the effect. */
effect->hweffect = (struct haptic_hweffect *) effect->hweffect = (struct haptic_hweffect *)
SDL_malloc(sizeof(struct haptic_hweffect)); SDL_malloc(sizeof(struct haptic_hweffect));
if (effect->hweffect == NULL) { if (!effect->hweffect) {
SDL_OutOfMemory(); SDL_OutOfMemory();
goto err_hweffect; goto err_hweffect;
} }
/* Get the type. */ /* Get the type. */
type = SDL_SYS_HapticEffectType(base->type); type = SDL_SYS_HapticEffectType(base->type);
if (type == NULL) { if (!type) {
goto err_hweffect; goto err_hweffect;
} }

View File

@ -188,7 +188,7 @@ static SDL_hapticlist_item *HapticByDevIndex(int device_index)
} }
while (device_index > 0) { while (device_index > 0) {
SDL_assert(item != NULL); SDL_assert(item);
--device_index; --device_index;
item = item->next; item = item->next;
} }
@ -199,7 +199,7 @@ static SDL_hapticlist_item *HapticByDevIndex(int device_index)
#ifdef SDL_USE_LIBUDEV #ifdef SDL_USE_LIBUDEV
static void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath) static void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath)
{ {
if (devpath == NULL || !(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) { if (!devpath || !(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
return; return;
} }
@ -225,7 +225,7 @@ static int MaybeAddDevice(const char *path)
int success; int success;
SDL_hapticlist_item *item; SDL_hapticlist_item *item;
if (path == NULL) { if (!path) {
return -1; return -1;
} }
@ -235,7 +235,7 @@ static int MaybeAddDevice(const char *path)
} }
/* check for duplicates */ /* check for duplicates */
for (item = SDL_hapticlist; item != NULL; item = item->next) { for (item = SDL_hapticlist; item; item = item->next) {
if (item->dev_num == sb.st_rdev) { if (item->dev_num == sb.st_rdev) {
return -1; /* duplicate. */ return -1; /* duplicate. */
} }
@ -259,12 +259,12 @@ static int MaybeAddDevice(const char *path)
} }
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item)); item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
if (item == NULL) { if (!item) {
return -1; return -1;
} }
item->fname = SDL_strdup(path); item->fname = SDL_strdup(path);
if (item->fname == NULL) { if (!item->fname) {
SDL_free(item); SDL_free(item);
return -1; return -1;
} }
@ -272,7 +272,7 @@ static int MaybeAddDevice(const char *path)
item->dev_num = sb.st_rdev; item->dev_num = sb.st_rdev;
/* TODO: should we add instance IDs? */ /* TODO: should we add instance IDs? */
if (SDL_hapticlist_tail == NULL) { if (!SDL_hapticlist_tail) {
SDL_hapticlist = SDL_hapticlist_tail = item; SDL_hapticlist = SDL_hapticlist_tail = item;
} else { } else {
SDL_hapticlist_tail->next = item; SDL_hapticlist_tail->next = item;
@ -292,16 +292,16 @@ static int MaybeRemoveDevice(const char *path)
SDL_hapticlist_item *item; SDL_hapticlist_item *item;
SDL_hapticlist_item *prev = NULL; SDL_hapticlist_item *prev = NULL;
if (path == NULL) { if (!path) {
return -1; return -1;
} }
for (item = SDL_hapticlist; item != NULL; item = item->next) { for (item = SDL_hapticlist; item; item = item->next) {
/* found it, remove it. */ /* found it, remove it. */
if (SDL_strcmp(path, item->fname) == 0) { if (SDL_strcmp(path, item->fname) == 0) {
const int retval = item->haptic ? item->haptic->index : -1; const int retval = item->haptic ? item->haptic->index : -1;
if (prev != NULL) { if (prev) {
prev->next = item->next; prev->next = item->next;
} else { } else {
SDL_assert(SDL_hapticlist == item); SDL_assert(SDL_hapticlist == item);
@ -358,7 +358,7 @@ const char *SDL_SYS_HapticName(int index)
if (fd >= 0) { if (fd >= 0) {
name = SDL_SYS_HapticNameFromFD(fd); name = SDL_SYS_HapticNameFromFD(fd);
if (name == NULL) { if (!name) {
/* No name found, return device character device */ /* No name found, return device character device */
name = item->fname; name = item->fname;
} }
@ -376,7 +376,7 @@ static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd)
/* Allocate the hwdata */ /* Allocate the hwdata */
haptic->hwdata = (struct haptic_hwdata *) haptic->hwdata = (struct haptic_hwdata *)
SDL_malloc(sizeof(*haptic->hwdata)); SDL_malloc(sizeof(*haptic->hwdata));
if (haptic->hwdata == NULL) { if (!haptic->hwdata) {
SDL_OutOfMemory(); SDL_OutOfMemory();
goto open_err; goto open_err;
} }
@ -396,7 +396,7 @@ static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd)
haptic->nplaying = haptic->neffects; /* Linux makes no distinction. */ haptic->nplaying = haptic->neffects; /* Linux makes no distinction. */
haptic->effects = (struct haptic_effect *) haptic->effects = (struct haptic_effect *)
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
if (haptic->effects == NULL) { if (!haptic->effects) {
SDL_OutOfMemory(); SDL_OutOfMemory();
goto open_err; goto open_err;
} }
@ -409,7 +409,7 @@ static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd)
/* Error handling */ /* Error handling */
open_err: open_err:
close(fd); close(fd);
if (haptic->hwdata != NULL) { if (haptic->hwdata) {
SDL_free(haptic->hwdata); SDL_free(haptic->hwdata);
haptic->hwdata = NULL; haptic->hwdata = NULL;
} }
@ -904,7 +904,7 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
/* Allocate the hardware effect */ /* Allocate the hardware effect */
effect->hweffect = (struct haptic_hweffect *) effect->hweffect = (struct haptic_hweffect *)
SDL_malloc(sizeof(struct haptic_hweffect)); SDL_malloc(sizeof(struct haptic_hweffect));
if (effect->hweffect == NULL) { if (!effect->hweffect) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }

View File

@ -92,7 +92,7 @@ int SDL_DINPUT_HapticInit(void)
/* Because we used CoCreateInstance, we need to Initialize it, first. */ /* Because we used CoCreateInstance, we need to Initialize it, first. */
instance = GetModuleHandle(NULL); instance = GetModuleHandle(NULL);
if (instance == NULL) { if (!instance) {
SDL_SYS_HapticQuit(); SDL_SYS_HapticQuit();
return SDL_SetError("GetModuleHandle() failed with error code %lu.", return SDL_SetError("GetModuleHandle() failed with error code %lu.",
GetLastError()); GetLastError());
@ -133,7 +133,7 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
DIDEVCAPS capabilities; DIDEVCAPS capabilities;
SDL_hapticlist_item *item = NULL; SDL_hapticlist_item *item = NULL;
if (dinput == NULL) { if (!dinput) {
return -1; /* not initialized. We'll pick these up on enumeration if we init later. */ return -1; /* not initialized. We'll pick these up on enumeration if we init later. */
} }
@ -166,7 +166,7 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
} }
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item)); item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
if (item == NULL) { if (!item) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -188,11 +188,11 @@ int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance)
SDL_hapticlist_item *item; SDL_hapticlist_item *item;
SDL_hapticlist_item *prev = NULL; SDL_hapticlist_item *prev = NULL;
if (dinput == NULL) { if (!dinput) {
return -1; /* not initialized, ignore this. */ return -1; /* not initialized, ignore this. */
} }
for (item = SDL_hapticlist; item != NULL; item = item->next) { for (item = SDL_hapticlist; item; item = item->next) {
if (!item->bXInputHaptic && SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0) { if (!item->bXInputHaptic && SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0) {
/* found it, remove it. */ /* found it, remove it. */
return SDL_SYS_RemoveHapticDevice(prev, item); return SDL_SYS_RemoveHapticDevice(prev, item);
@ -287,7 +287,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
/* Allocate the hwdata */ /* Allocate the hwdata */
haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata)); haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata));
if (haptic->hwdata == NULL) { if (!haptic->hwdata) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
@ -401,7 +401,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
/* Prepare effects memory. */ /* Prepare effects memory. */
haptic->effects = (struct haptic_effect *) haptic->effects = (struct haptic_effect *)
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
if (haptic->effects == NULL) { if (!haptic->effects) {
SDL_OutOfMemory(); SDL_OutOfMemory();
goto acquire_err; goto acquire_err;
} }
@ -474,7 +474,7 @@ int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick
} }
/* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */ /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
for (item = SDL_hapticlist; item != NULL; item = item->next) { for (item = SDL_hapticlist; item; item = item->next) {
if (!item->bXInputHaptic && WIN_IsEqualGUID(&item->instance.guidInstance, &joy_instance.guidInstance)) { if (!item->bXInputHaptic && WIN_IsEqualGUID(&item->instance.guidInstance, &joy_instance.guidInstance)) {
haptic->index = index; haptic->index = index;
return SDL_DINPUT_HapticOpenFromDevice(haptic, joystick->hwdata->InputDevice, SDL_TRUE); return SDL_DINPUT_HapticOpenFromDevice(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
@ -540,7 +540,7 @@ static int SDL_SYS_SetDirection(DIEFFECT *effect, SDL_HapticDirection *dir, int
/* Has axes. */ /* Has axes. */
rglDir = SDL_malloc(sizeof(LONG) * naxes); rglDir = SDL_malloc(sizeof(LONG) * naxes);
if (rglDir == NULL) { if (!rglDir) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(rglDir, 0, sizeof(LONG) * naxes); SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
@ -614,7 +614,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
/* Envelope. */ /* Envelope. */
envelope = SDL_malloc(sizeof(DIENVELOPE)); envelope = SDL_malloc(sizeof(DIENVELOPE));
if (envelope == NULL) { if (!envelope) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(envelope, 0, sizeof(DIENVELOPE)); SDL_memset(envelope, 0, sizeof(DIENVELOPE));
@ -629,7 +629,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
} }
if (dest->cAxes > 0) { if (dest->cAxes > 0) {
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes); axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
if (axes == NULL) { if (!axes) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */ axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
@ -647,7 +647,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
case SDL_HAPTIC_CONSTANT: case SDL_HAPTIC_CONSTANT:
hap_constant = &src->constant; hap_constant = &src->constant;
constant = SDL_malloc(sizeof(DICONSTANTFORCE)); constant = SDL_malloc(sizeof(DICONSTANTFORCE));
if (constant == NULL) { if (!constant) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(constant, 0, sizeof(DICONSTANTFORCE)); SDL_memset(constant, 0, sizeof(DICONSTANTFORCE));
@ -689,7 +689,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
case SDL_HAPTIC_SAWTOOTHDOWN: case SDL_HAPTIC_SAWTOOTHDOWN:
hap_periodic = &src->periodic; hap_periodic = &src->periodic;
periodic = SDL_malloc(sizeof(DIPERIODIC)); periodic = SDL_malloc(sizeof(DIPERIODIC));
if (periodic == NULL) { if (!periodic) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(periodic, 0, sizeof(DIPERIODIC)); SDL_memset(periodic, 0, sizeof(DIPERIODIC));
@ -733,7 +733,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
case SDL_HAPTIC_FRICTION: case SDL_HAPTIC_FRICTION:
hap_condition = &src->condition; hap_condition = &src->condition;
condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes); condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes);
if (condition == NULL) { if (!condition) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(condition, 0, sizeof(DICONDITION)); SDL_memset(condition, 0, sizeof(DICONDITION));
@ -774,7 +774,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
case SDL_HAPTIC_RAMP: case SDL_HAPTIC_RAMP:
hap_ramp = &src->ramp; hap_ramp = &src->ramp;
ramp = SDL_malloc(sizeof(DIRAMPFORCE)); ramp = SDL_malloc(sizeof(DIRAMPFORCE));
if (ramp == NULL) { if (!ramp) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(ramp, 0, sizeof(DIRAMPFORCE)); SDL_memset(ramp, 0, sizeof(DIRAMPFORCE));
@ -812,7 +812,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
case SDL_HAPTIC_CUSTOM: case SDL_HAPTIC_CUSTOM:
hap_custom = &src->custom; hap_custom = &src->custom;
custom = SDL_malloc(sizeof(DICUSTOMFORCE)); custom = SDL_malloc(sizeof(DICUSTOMFORCE));
if (custom == NULL) { if (!custom) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(custom, 0, sizeof(DICUSTOMFORCE)); SDL_memset(custom, 0, sizeof(DICUSTOMFORCE));
@ -871,7 +871,7 @@ static void SDL_SYS_HapticFreeDIEFFECT(DIEFFECT *effect, int type)
effect->lpEnvelope = NULL; effect->lpEnvelope = NULL;
SDL_free(effect->rgdwAxes); SDL_free(effect->rgdwAxes);
effect->rgdwAxes = NULL; effect->rgdwAxes = NULL;
if (effect->lpvTypeSpecificParams != NULL) { if (effect->lpvTypeSpecificParams) {
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */ if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
custom = (DICUSTOMFORCE *)effect->lpvTypeSpecificParams; custom = (DICUSTOMFORCE *)effect->lpvTypeSpecificParams;
SDL_free(custom->rglForceData); SDL_free(custom->rglForceData);
@ -937,7 +937,7 @@ int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
HRESULT ret; HRESULT ret;
REFGUID type = SDL_SYS_HapticEffectType(base); REFGUID type = SDL_SYS_HapticEffectType(base);
if (type == NULL) { if (!type) {
return SDL_SetError("Haptic: Unknown effect type."); return SDL_SetError("Haptic: Unknown effect type.");
} }

View File

@ -75,7 +75,7 @@ int SDL_SYS_HapticInit(void)
int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item) int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item)
{ {
if (SDL_hapticlist_tail == NULL) { if (!SDL_hapticlist_tail) {
SDL_hapticlist = SDL_hapticlist_tail = item; SDL_hapticlist = SDL_hapticlist_tail = item;
} else { } else {
SDL_hapticlist_tail->next = item; SDL_hapticlist_tail->next = item;
@ -91,7 +91,7 @@ int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item)
int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item) int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item)
{ {
const int retval = item->haptic ? item->haptic->index : -1; const int retval = item->haptic ? item->haptic->index : -1;
if (prev != NULL) { if (prev) {
prev->next = item->next; prev->next = item->next;
} else { } else {
SDL_assert(SDL_hapticlist == item); SDL_assert(SDL_hapticlist == item);
@ -120,7 +120,7 @@ static SDL_hapticlist_item *HapticByDevIndex(int device_index)
} }
while (device_index > 0) { while (device_index > 0) {
SDL_assert(item != NULL); SDL_assert(item);
--device_index; --device_index;
item = item->next; item = item->next;
} }
@ -159,7 +159,7 @@ int SDL_SYS_HapticMouse(void)
int index = 0; int index = 0;
/* Grab the first mouse haptic device we find. */ /* Grab the first mouse haptic device we find. */
for (item = SDL_hapticlist; item != NULL; item = item->next) { for (item = SDL_hapticlist; item; item = item->next) {
if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER) { if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER) {
return index; return index;
} }
@ -293,7 +293,7 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
/* Alloc the effect. */ /* Alloc the effect. */
effect->hweffect = (struct haptic_hweffect *) effect->hweffect = (struct haptic_hweffect *)
SDL_malloc(sizeof(struct haptic_hweffect)); SDL_malloc(sizeof(struct haptic_hweffect));
if (effect->hweffect == NULL) { if (!effect->hweffect) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }

View File

@ -79,7 +79,7 @@ int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
} }
item = (SDL_hapticlist_item *)SDL_malloc(sizeof(SDL_hapticlist_item)); item = (SDL_hapticlist_item *)SDL_malloc(sizeof(SDL_hapticlist_item));
if (item == NULL) { if (!item) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -114,7 +114,7 @@ int SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid)
return -1; return -1;
} }
for (item = SDL_hapticlist; item != NULL; item = item->next) { for (item = SDL_hapticlist; item; item = item->next) {
if (item->bXInputHaptic && item->userid == userid) { if (item->bXInputHaptic && item->userid == userid) {
/* found it, remove it. */ /* found it, remove it. */
return SDL_SYS_RemoveHapticDevice(prev, item); return SDL_SYS_RemoveHapticDevice(prev, item);
@ -173,7 +173,7 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us
/* Prepare effects memory. */ /* Prepare effects memory. */
haptic->effects = (struct haptic_effect *) haptic->effects = (struct haptic_effect *)
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
if (haptic->effects == NULL) { if (!haptic->effects) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
/* Clear the memory */ /* Clear the memory */
@ -181,7 +181,7 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us
sizeof(struct haptic_effect) * haptic->neffects); sizeof(struct haptic_effect) * haptic->neffects);
haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata)); haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata));
if (haptic->hwdata == NULL) { if (!haptic->hwdata) {
SDL_free(haptic->effects); SDL_free(haptic->effects);
haptic->effects = NULL; haptic->effects = NULL;
return SDL_OutOfMemory(); return SDL_OutOfMemory();
@ -192,7 +192,7 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us
haptic->hwdata->userid = userid; haptic->hwdata->userid = userid;
haptic->hwdata->mutex = SDL_CreateMutex(); haptic->hwdata->mutex = SDL_CreateMutex();
if (haptic->hwdata->mutex == NULL) { if (!haptic->hwdata->mutex) {
SDL_free(haptic->effects); SDL_free(haptic->effects);
SDL_free(haptic->hwdata); SDL_free(haptic->hwdata);
haptic->effects = NULL; haptic->effects = NULL;
@ -202,7 +202,7 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us
(void)SDL_snprintf(threadName, sizeof(threadName), "SDLXInputDev%d", userid); (void)SDL_snprintf(threadName, sizeof(threadName), "SDLXInputDev%d", userid);
haptic->hwdata->thread = SDL_CreateThreadInternal(SDL_RunXInputHaptic, threadName, 64 * 1024, haptic->hwdata); haptic->hwdata->thread = SDL_CreateThreadInternal(SDL_RunXInputHaptic, threadName, 64 * 1024, haptic->hwdata);
if (haptic->hwdata->thread == NULL) { if (!haptic->hwdata->thread) {
SDL_DestroyMutex(haptic->hwdata->mutex); SDL_DestroyMutex(haptic->hwdata->mutex);
SDL_free(haptic->effects); SDL_free(haptic->effects);
SDL_free(haptic->hwdata); SDL_free(haptic->hwdata);
@ -229,7 +229,7 @@ int SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick
Uint8 index = 0; Uint8 index = 0;
/* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */ /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
for (item = SDL_hapticlist; item != NULL; item = item->next) { for (item = SDL_hapticlist; item; item = item->next) {
if (item->bXInputHaptic && item->userid == joystick->hwdata->userid) { if (item->bXInputHaptic && item->userid == joystick->hwdata->userid) {
haptic->index = index; haptic->index = index;
return SDL_XINPUT_HapticOpenFromUserIndex(haptic, joystick->hwdata->userid); return SDL_XINPUT_HapticOpenFromUserIndex(haptic, joystick->hwdata->userid);

View File

@ -197,7 +197,7 @@ static void HandleJoystickAxis(Uint64 timestamp, SDL_Gamepad *gamepad, int axis,
} }
} }
if (last_match && (match == NULL || !HasSameOutput(last_match, match))) { if (last_match && (!match || !HasSameOutput(last_match, match))) {
/* Clear the last input that this axis generated */ /* Clear the last input that this axis generated */
ResetOutput(timestamp, gamepad, last_match); ResetOutput(timestamp, gamepad, last_match);
} }
@ -987,7 +987,7 @@ SDL_GamepadType SDL_GetGamepadTypeFromString(const char *str)
{ {
int i; int i;
if (str == NULL || str[0] == '\0') { if (!str || str[0] == '\0') {
return SDL_GAMEPAD_TYPE_UNKNOWN; return SDL_GAMEPAD_TYPE_UNKNOWN;
} }
@ -1031,7 +1031,7 @@ SDL_GamepadAxis SDL_GetGamepadAxisFromString(const char *str)
{ {
int i; int i;
if (str == NULL || str[0] == '\0') { if (!str || str[0] == '\0') {
return SDL_GAMEPAD_AXIS_INVALID; return SDL_GAMEPAD_AXIS_INVALID;
} }
@ -1090,7 +1090,7 @@ SDL_GamepadButton SDL_GetGamepadButtonFromString(const char *str)
{ {
int i; int i;
if (str == NULL || str[0] == '\0') { if (!str || str[0] == '\0') {
return SDL_GAMEPAD_BUTTON_INVALID; return SDL_GAMEPAD_BUTTON_INVALID;
} }
@ -1269,7 +1269,7 @@ static void SDL_PrivateLoadButtonMapping(SDL_Gamepad *gamepad, GamepadMapping_t
gamepad->name = pGamepadMapping->name; gamepad->name = pGamepadMapping->name;
gamepad->num_bindings = 0; gamepad->num_bindings = 0;
gamepad->mapping = pGamepadMapping; gamepad->mapping = pGamepadMapping;
if (gamepad->joystick->naxes != 0 && gamepad->last_match_axis != NULL) { if (gamepad->joystick->naxes != 0 && gamepad->last_match_axis) {
SDL_memset(gamepad->last_match_axis, 0, gamepad->joystick->naxes * sizeof(*gamepad->last_match_axis)); SDL_memset(gamepad->last_match_axis, 0, gamepad->joystick->naxes * sizeof(*gamepad->last_match_axis));
} }
@ -1298,7 +1298,7 @@ static char *SDL_PrivateGetGamepadGUIDFromMappingString(const char *pMapping)
const char *pFirstComma = SDL_strchr(pMapping, ','); const char *pFirstComma = SDL_strchr(pMapping, ',');
if (pFirstComma) { if (pFirstComma) {
char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1); char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1);
if (pchGUID == NULL) { if (!pchGUID) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
@ -1337,17 +1337,17 @@ static char *SDL_PrivateGetGamepadNameFromMappingString(const char *pMapping)
char *pchName; char *pchName;
pFirstComma = SDL_strchr(pMapping, ','); pFirstComma = SDL_strchr(pMapping, ',');
if (pFirstComma == NULL) { if (!pFirstComma) {
return NULL; return NULL;
} }
pSecondComma = SDL_strchr(pFirstComma + 1, ','); pSecondComma = SDL_strchr(pFirstComma + 1, ',');
if (pSecondComma == NULL) { if (!pSecondComma) {
return NULL; return NULL;
} }
pchName = SDL_malloc(pSecondComma - pFirstComma); pchName = SDL_malloc(pSecondComma - pFirstComma);
if (pchName == NULL) { if (!pchName) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
@ -1366,12 +1366,12 @@ static char *SDL_PrivateGetGamepadMappingFromMappingString(const char *pMapping)
size_t length; size_t length;
pFirstComma = SDL_strchr(pMapping, ','); pFirstComma = SDL_strchr(pMapping, ',');
if (pFirstComma == NULL) { if (!pFirstComma) {
return NULL; return NULL;
} }
pSecondComma = SDL_strchr(pFirstComma + 1, ','); pSecondComma = SDL_strchr(pFirstComma + 1, ',');
if (pSecondComma == NULL) { if (!pSecondComma) {
return NULL; return NULL;
} }
@ -1405,13 +1405,13 @@ static GamepadMapping_t *SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, co
SDL_AssertJoysticksLocked(); SDL_AssertJoysticksLocked();
pchName = SDL_PrivateGetGamepadNameFromMappingString(mappingString); pchName = SDL_PrivateGetGamepadNameFromMappingString(mappingString);
if (pchName == NULL) { if (!pchName) {
SDL_SetError("Couldn't parse name from %s", mappingString); SDL_SetError("Couldn't parse name from %s", mappingString);
return NULL; return NULL;
} }
pchMapping = SDL_PrivateGetGamepadMappingFromMappingString(mappingString); pchMapping = SDL_PrivateGetGamepadMappingFromMappingString(mappingString);
if (pchMapping == NULL) { if (!pchMapping) {
SDL_free(pchName); SDL_free(pchName);
SDL_SetError("Couldn't parse %s", mappingString); SDL_SetError("Couldn't parse %s", mappingString);
return NULL; return NULL;
@ -1481,7 +1481,7 @@ static GamepadMapping_t *SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, co
AddMappingChangeTracking(pGamepadMapping); AddMappingChangeTracking(pGamepadMapping);
} else { } else {
pGamepadMapping = SDL_malloc(sizeof(*pGamepadMapping)); pGamepadMapping = SDL_malloc(sizeof(*pGamepadMapping));
if (pGamepadMapping == NULL) { if (!pGamepadMapping) {
PopMappingChangeTracking(); PopMappingChangeTracking();
SDL_free(pchName); SDL_free(pchName);
SDL_free(pchMapping); SDL_free(pchMapping);
@ -1532,7 +1532,7 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMappingForNameAndGUID(const char *
mapping = SDL_PrivateGetGamepadMappingForGUID(guid, SDL_FALSE); mapping = SDL_PrivateGetGamepadMappingForGUID(guid, SDL_FALSE);
#ifdef __LINUX__ #ifdef __LINUX__
if (mapping == NULL && name) { if (!mapping && name) {
if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) { if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
/* The Linux driver xpad.c maps the wireless dpad to buttons */ /* The Linux driver xpad.c maps the wireless dpad to buttons */
SDL_bool existing; SDL_bool existing;
@ -1543,7 +1543,7 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMappingForNameAndGUID(const char *
} }
#endif /* __LINUX__ */ #endif /* __LINUX__ */
if (mapping == NULL) { if (!mapping) {
mapping = s_pDefaultMapping; mapping = s_pDefaultMapping;
} }
return mapping; return mapping;
@ -1641,7 +1641,7 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMapping(SDL_JoystickID instance_id
name = SDL_GetJoystickInstanceName(instance_id); name = SDL_GetJoystickInstanceName(instance_id);
guid = SDL_GetJoystickInstanceGUID(instance_id); guid = SDL_GetJoystickInstanceGUID(instance_id);
mapping = SDL_PrivateGetGamepadMappingForNameAndGUID(name, guid); mapping = SDL_PrivateGetGamepadMappingForNameAndGUID(name, guid);
if (mapping == NULL) { if (!mapping) {
SDL_GamepadMapping raw_map; SDL_GamepadMapping raw_map;
SDL_zero(raw_map); SDL_zero(raw_map);
@ -1665,7 +1665,7 @@ int SDL_AddGamepadMappingsFromRW(SDL_RWops *src, SDL_bool freesrc)
size_t platform_len; size_t platform_len;
buf = (char *)SDL_LoadFile_RW(src, &db_size, freesrc); buf = (char *)SDL_LoadFile_RW(src, &db_size, freesrc);
if (buf == NULL) { if (!buf) {
return SDL_SetError("Could not allocate space to read DB into memory"); return SDL_SetError("Could not allocate space to read DB into memory");
} }
line = buf; line = buf;
@ -1676,7 +1676,7 @@ int SDL_AddGamepadMappingsFromRW(SDL_RWops *src, SDL_bool freesrc)
while (line < buf + db_size) { while (line < buf + db_size) {
line_end = SDL_strchr(line, '\n'); line_end = SDL_strchr(line, '\n');
if (line_end != NULL) { if (line_end) {
*line_end = '\0'; *line_end = '\0';
} else { } else {
line_end = buf + db_size; line_end = buf + db_size;
@ -1684,10 +1684,10 @@ int SDL_AddGamepadMappingsFromRW(SDL_RWops *src, SDL_bool freesrc)
/* Extract and verify the platform */ /* Extract and verify the platform */
tmp = SDL_strstr(line, SDL_GAMEPAD_PLATFORM_FIELD); tmp = SDL_strstr(line, SDL_GAMEPAD_PLATFORM_FIELD);
if (tmp != NULL) { if (tmp) {
tmp += SDL_GAMEPAD_PLATFORM_FIELD_SIZE; tmp += SDL_GAMEPAD_PLATFORM_FIELD_SIZE;
comma = SDL_strchr(tmp, ','); comma = SDL_strchr(tmp, ',');
if (comma != NULL) { if (comma) {
platform_len = comma - tmp + 1; platform_len = comma - tmp + 1;
if (platform_len + 1 < SDL_arraysize(line_platform)) { if (platform_len + 1 < SDL_arraysize(line_platform)) {
SDL_strlcpy(line_platform, tmp, platform_len); SDL_strlcpy(line_platform, tmp, platform_len);
@ -1751,7 +1751,7 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa
SDL_AssertJoysticksLocked(); SDL_AssertJoysticksLocked();
if (mappingString == NULL) { if (!mappingString) {
return SDL_InvalidParamError("mappingString"); return SDL_InvalidParamError("mappingString");
} }
@ -1759,7 +1759,7 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa
const char *tmp; const char *tmp;
tmp = SDL_strstr(mappingString, SDL_GAMEPAD_HINT_FIELD); tmp = SDL_strstr(mappingString, SDL_GAMEPAD_HINT_FIELD);
if (tmp != NULL) { if (tmp) {
SDL_bool default_value, value, negate; SDL_bool default_value, value, negate;
int len; int len;
char hint[128]; char hint[128];
@ -1801,14 +1801,14 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa
const char *tmp; const char *tmp;
tmp = SDL_strstr(mappingString, SDL_GAMEPAD_SDKGE_FIELD); tmp = SDL_strstr(mappingString, SDL_GAMEPAD_SDKGE_FIELD);
if (tmp != NULL) { if (tmp) {
tmp += SDL_GAMEPAD_SDKGE_FIELD_SIZE; tmp += SDL_GAMEPAD_SDKGE_FIELD_SIZE;
if (!(SDL_GetAndroidSDKVersion() >= SDL_atoi(tmp))) { if (!(SDL_GetAndroidSDKVersion() >= SDL_atoi(tmp))) {
return SDL_SetError("SDK version %d < minimum version %d", SDL_GetAndroidSDKVersion(), SDL_atoi(tmp)); return SDL_SetError("SDK version %d < minimum version %d", SDL_GetAndroidSDKVersion(), SDL_atoi(tmp));
} }
} }
tmp = SDL_strstr(mappingString, SDL_GAMEPAD_SDKLE_FIELD); tmp = SDL_strstr(mappingString, SDL_GAMEPAD_SDKLE_FIELD);
if (tmp != NULL) { if (tmp) {
tmp += SDL_GAMEPAD_SDKLE_FIELD_SIZE; tmp += SDL_GAMEPAD_SDKLE_FIELD_SIZE;
if (!(SDL_GetAndroidSDKVersion() <= SDL_atoi(tmp))) { if (!(SDL_GetAndroidSDKVersion() <= SDL_atoi(tmp))) {
return SDL_SetError("SDK version %d > maximum version %d", SDL_GetAndroidSDKVersion(), SDL_atoi(tmp)); return SDL_SetError("SDK version %d > maximum version %d", SDL_GetAndroidSDKVersion(), SDL_atoi(tmp));
@ -1818,7 +1818,7 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa
#endif #endif
pchGUID = SDL_PrivateGetGamepadGUIDFromMappingString(mappingString); pchGUID = SDL_PrivateGetGamepadGUIDFromMappingString(mappingString);
if (pchGUID == NULL) { if (!pchGUID) {
return SDL_SetError("Couldn't parse GUID from %s", mappingString); return SDL_SetError("Couldn't parse GUID from %s", mappingString);
} }
if (!SDL_strcasecmp(pchGUID, "default")) { if (!SDL_strcasecmp(pchGUID, "default")) {
@ -1830,7 +1830,7 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa
SDL_free(pchGUID); SDL_free(pchGUID);
pGamepadMapping = SDL_PrivateAddMappingForGUID(jGUID, mappingString, &existing, priority); pGamepadMapping = SDL_PrivateAddMappingForGUID(jGUID, mappingString, &existing, priority);
if (pGamepadMapping == NULL) { if (!pGamepadMapping) {
return -1; return -1;
} }
@ -1914,7 +1914,7 @@ static char *CreateMappingString(GamepadMapping_t *mapping, SDL_JoystickGUID gui
} }
pMappingString = SDL_malloc(needed); pMappingString = SDL_malloc(needed);
if (pMappingString == NULL) { if (!pMappingString) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
@ -1965,7 +1965,7 @@ char *SDL_GetGamepadMappingForIndex(int mapping_index)
} }
SDL_UnlockJoysticks(); SDL_UnlockJoysticks();
if (retval == NULL) { if (!retval) {
SDL_SetError("Mapping not available"); SDL_SetError("Mapping not available");
} }
return retval; return retval;
@ -2179,7 +2179,7 @@ const char *SDL_GetGamepadInstanceName(SDL_JoystickID instance_id)
SDL_LockJoysticks(); SDL_LockJoysticks();
{ {
GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id); GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id);
if (mapping != NULL) { if (mapping) {
if (SDL_strcmp(mapping->name, "*") == 0) { if (SDL_strcmp(mapping->name, "*") == 0) {
retval = SDL_GetJoystickInstanceName(instance_id); retval = SDL_GetJoystickInstanceName(instance_id);
} else { } else {
@ -2229,14 +2229,14 @@ SDL_GamepadType SDL_GetGamepadInstanceType(SDL_JoystickID instance_id)
SDL_LockJoysticks(); SDL_LockJoysticks();
{ {
GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id); GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id);
if (mapping != NULL) { if (mapping) {
char *type_string, *comma; char *type_string, *comma;
type_string = SDL_strstr(mapping->mapping, SDL_GAMEPAD_TYPE_FIELD); type_string = SDL_strstr(mapping->mapping, SDL_GAMEPAD_TYPE_FIELD);
if (type_string != NULL) { if (type_string) {
type_string += SDL_GAMEPAD_TYPE_FIELD_SIZE; type_string += SDL_GAMEPAD_TYPE_FIELD_SIZE;
comma = SDL_strchr(type_string, ','); comma = SDL_strchr(type_string, ',');
if (comma != NULL) { if (comma) {
*comma = '\0'; *comma = '\0';
type = SDL_GetGamepadTypeFromString(type_string); type = SDL_GetGamepadTypeFromString(type_string);
*comma = ','; *comma = ',';
@ -2265,7 +2265,7 @@ char *SDL_GetGamepadInstanceMapping(SDL_JoystickID instance_id)
SDL_LockJoysticks(); SDL_LockJoysticks();
{ {
GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id); GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id);
if (mapping != NULL) { if (mapping) {
SDL_JoystickGUID guid; SDL_JoystickGUID guid;
char pchGUID[33]; char pchGUID[33];
size_t needed; size_t needed;
@ -2274,7 +2274,7 @@ char *SDL_GetGamepadInstanceMapping(SDL_JoystickID instance_id)
/* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */ /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1; needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
retval = (char *)SDL_malloc(needed); retval = (char *)SDL_malloc(needed);
if (retval != NULL) { if (retval) {
(void)SDL_snprintf(retval, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping); (void)SDL_snprintf(retval, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
} else { } else {
SDL_OutOfMemory(); SDL_OutOfMemory();
@ -2409,7 +2409,7 @@ SDL_Gamepad *SDL_OpenGamepad(SDL_JoystickID instance_id)
gamepadlist = SDL_gamepads; gamepadlist = SDL_gamepads;
/* If the gamepad is already open, return it */ /* If the gamepad is already open, return it */
while (gamepadlist != NULL) { while (gamepadlist) {
if (instance_id == gamepadlist->joystick->instance_id) { if (instance_id == gamepadlist->joystick->instance_id) {
gamepad = gamepadlist; gamepad = gamepadlist;
++gamepad->ref_count; ++gamepad->ref_count;
@ -2421,7 +2421,7 @@ SDL_Gamepad *SDL_OpenGamepad(SDL_JoystickID instance_id)
/* Find a gamepad mapping */ /* Find a gamepad mapping */
pSupportedGamepad = SDL_PrivateGetGamepadMapping(instance_id); pSupportedGamepad = SDL_PrivateGetGamepadMapping(instance_id);
if (pSupportedGamepad == NULL) { if (!pSupportedGamepad) {
SDL_SetError("Couldn't find mapping for device (%" SDL_PRIu32 ")", instance_id); SDL_SetError("Couldn't find mapping for device (%" SDL_PRIu32 ")", instance_id);
SDL_UnlockJoysticks(); SDL_UnlockJoysticks();
return NULL; return NULL;
@ -2429,7 +2429,7 @@ SDL_Gamepad *SDL_OpenGamepad(SDL_JoystickID instance_id)
/* Create and initialize the gamepad */ /* Create and initialize the gamepad */
gamepad = (SDL_Gamepad *)SDL_calloc(1, sizeof(*gamepad)); gamepad = (SDL_Gamepad *)SDL_calloc(1, sizeof(*gamepad));
if (gamepad == NULL) { if (!gamepad) {
SDL_OutOfMemory(); SDL_OutOfMemory();
SDL_UnlockJoysticks(); SDL_UnlockJoysticks();
return NULL; return NULL;
@ -2437,7 +2437,7 @@ SDL_Gamepad *SDL_OpenGamepad(SDL_JoystickID instance_id)
gamepad->magic = &gamepad_magic; gamepad->magic = &gamepad_magic;
gamepad->joystick = SDL_OpenJoystick(instance_id); gamepad->joystick = SDL_OpenJoystick(instance_id);
if (gamepad->joystick == NULL) { if (!gamepad->joystick) {
SDL_free(gamepad); SDL_free(gamepad);
SDL_UnlockJoysticks(); SDL_UnlockJoysticks();
return NULL; return NULL;
@ -2923,7 +2923,7 @@ SDL_JoystickID SDL_GetGamepadInstanceID(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return 0; return 0;
} }
return SDL_GetJoystickInstanceID(joystick); return SDL_GetJoystickInstanceID(joystick);
@ -2967,7 +2967,7 @@ const char *SDL_GetGamepadPath(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return NULL; return NULL;
} }
return SDL_GetJoystickPath(joystick); return SDL_GetJoystickPath(joystick);
@ -2992,7 +2992,7 @@ SDL_GamepadType SDL_GetRealGamepadType(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return SDL_GAMEPAD_TYPE_UNKNOWN; return SDL_GAMEPAD_TYPE_UNKNOWN;
} }
return SDL_GetGamepadTypeFromGUID(SDL_GetJoystickGUID(joystick), SDL_GetJoystickName(joystick)); return SDL_GetGamepadTypeFromGUID(SDL_GetJoystickGUID(joystick), SDL_GetJoystickName(joystick));
@ -3002,7 +3002,7 @@ int SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return -1; return -1;
} }
return SDL_GetJoystickPlayerIndex(joystick); return SDL_GetJoystickPlayerIndex(joystick);
@ -3015,7 +3015,7 @@ int SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
/* SDL_SetError() will have been called already by SDL_GetGamepadJoystick() */ /* SDL_SetError() will have been called already by SDL_GetGamepadJoystick() */
return -1; return -1;
} }
@ -3026,7 +3026,7 @@ Uint16 SDL_GetGamepadVendor(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return 0; return 0;
} }
return SDL_GetJoystickVendor(joystick); return SDL_GetJoystickVendor(joystick);
@ -3036,7 +3036,7 @@ Uint16 SDL_GetGamepadProduct(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return 0; return 0;
} }
return SDL_GetJoystickProduct(joystick); return SDL_GetJoystickProduct(joystick);
@ -3046,7 +3046,7 @@ Uint16 SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return 0; return 0;
} }
return SDL_GetJoystickProductVersion(joystick); return SDL_GetJoystickProductVersion(joystick);
@ -3056,7 +3056,7 @@ Uint16 SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return 0; return 0;
} }
return SDL_GetJoystickFirmwareVersion(joystick); return SDL_GetJoystickFirmwareVersion(joystick);
@ -3066,7 +3066,7 @@ const char * SDL_GetGamepadSerial(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return NULL; return NULL;
} }
return SDL_GetJoystickSerial(joystick); return SDL_GetJoystickSerial(joystick);
@ -3076,7 +3076,7 @@ SDL_JoystickPowerLevel SDL_GetGamepadPowerLevel(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return SDL_JOYSTICK_POWER_UNKNOWN; return SDL_JOYSTICK_POWER_UNKNOWN;
} }
return SDL_GetJoystickPowerLevel(joystick); return SDL_GetJoystickPowerLevel(joystick);
@ -3090,7 +3090,7 @@ SDL_bool SDL_GamepadConnected(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return SDL_FALSE; return SDL_FALSE;
} }
return SDL_JoystickConnected(joystick); return SDL_JoystickConnected(joystick);
@ -3196,7 +3196,7 @@ int SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return -1; return -1;
} }
return SDL_RumbleJoystick(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms); return SDL_RumbleJoystick(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
@ -3206,7 +3206,7 @@ int SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 r
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return -1; return -1;
} }
return SDL_RumbleJoystickTriggers(joystick, left_rumble, right_rumble, duration_ms); return SDL_RumbleJoystickTriggers(joystick, left_rumble, right_rumble, duration_ms);
@ -3216,7 +3216,7 @@ SDL_bool SDL_GamepadHasLED(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return SDL_FALSE; return SDL_FALSE;
} }
return SDL_JoystickHasLED(joystick); return SDL_JoystickHasLED(joystick);
@ -3226,7 +3226,7 @@ SDL_bool SDL_GamepadHasRumble(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return SDL_FALSE; return SDL_FALSE;
} }
return SDL_JoystickHasRumble(joystick); return SDL_JoystickHasRumble(joystick);
@ -3236,7 +3236,7 @@ SDL_bool SDL_GamepadHasRumbleTriggers(SDL_Gamepad *gamepad)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return SDL_FALSE; return SDL_FALSE;
} }
return SDL_JoystickHasRumbleTriggers(joystick); return SDL_JoystickHasRumbleTriggers(joystick);
@ -3246,7 +3246,7 @@ int SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return -1; return -1;
} }
return SDL_SetJoystickLED(joystick, red, green, blue); return SDL_SetJoystickLED(joystick, red, green, blue);
@ -3256,7 +3256,7 @@ int SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
if (joystick == NULL) { if (!joystick) {
return -1; return -1;
} }
return SDL_SendJoystickEffect(joystick, data, size); return SDL_SendJoystickEffect(joystick, data, size);
@ -3268,7 +3268,7 @@ void SDL_CloseGamepad(SDL_Gamepad *gamepad)
SDL_LockJoysticks(); SDL_LockJoysticks();
if (gamepad == NULL || gamepad->magic != &gamepad_magic) { if (!gamepad || gamepad->magic != &gamepad_magic) {
SDL_UnlockJoysticks(); SDL_UnlockJoysticks();
return; return;
} }

View File

@ -269,7 +269,7 @@ static SDL_bool SDL_SetJoystickIDForPlayerIndex(int player_index, SDL_JoystickID
if (player_index >= SDL_joystick_player_count) { if (player_index >= SDL_joystick_player_count) {
SDL_JoystickID *new_players = (SDL_JoystickID *)SDL_realloc(SDL_joystick_players, (player_index + 1) * sizeof(*SDL_joystick_players)); SDL_JoystickID *new_players = (SDL_JoystickID *)SDL_realloc(SDL_joystick_players, (player_index + 1) * sizeof(*SDL_joystick_players));
if (new_players == NULL) { if (!new_players) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;
} }
@ -447,7 +447,7 @@ const char *SDL_GetJoystickInstancePath(SDL_JoystickID instance_id)
SDL_UnlockJoysticks(); SDL_UnlockJoysticks();
/* FIXME: Really we should reference count this path so it doesn't go away after unlock */ /* FIXME: Really we should reference count this path so it doesn't go away after unlock */
if (path == NULL) { if (!path) {
SDL_Unsupported(); SDL_Unsupported();
} }
return path; return path;
@ -754,7 +754,7 @@ SDL_Joystick *SDL_OpenJoystick(SDL_JoystickID instance_id)
/* Create and initialize the joystick */ /* Create and initialize the joystick */
joystick = (SDL_Joystick *)SDL_calloc(sizeof(*joystick), 1); joystick = (SDL_Joystick *)SDL_calloc(sizeof(*joystick), 1);
if (joystick == NULL) { if (!joystick) {
SDL_OutOfMemory(); SDL_OutOfMemory();
SDL_UnlockJoysticks(); SDL_UnlockJoysticks();
return NULL; return NULL;
@ -2145,10 +2145,10 @@ char *SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_n
return SDL_strdup(custom_name); return SDL_strdup(custom_name);
} }
if (vendor_name == NULL) { if (!vendor_name) {
vendor_name = ""; vendor_name = "";
} }
if (product_name == NULL) { if (!product_name) {
product_name = ""; product_name = "";
} }
@ -2191,7 +2191,7 @@ char *SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_n
default: default:
len = (6 + 1 + 6 + 1); len = (6 + 1 + 6 + 1);
name = (char *)SDL_malloc(len); name = (char *)SDL_malloc(len);
if (name != NULL) { if (name) {
(void)SDL_snprintf(name, len, "0x%.4x/0x%.4x", vendor, product); (void)SDL_snprintf(name, len, "0x%.4x/0x%.4x", vendor, product);
} }
break; break;
@ -2200,7 +2200,7 @@ char *SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_n
name = SDL_strdup("Controller"); name = SDL_strdup("Controller");
} }
if (name == NULL) { if (!name) {
return NULL; return NULL;
} }
@ -2264,7 +2264,7 @@ SDL_JoystickGUID SDL_CreateJoystickGUID(Uint16 bus, Uint16 vendor, Uint16 produc
SDL_zero(guid); SDL_zero(guid);
if (name == NULL) { if (!name) {
name = ""; name = "";
} }
@ -3367,7 +3367,7 @@ void SDL_LoadVIDPIDListFromHint(const char *hint, SDL_vidpid_list *list)
spot = (char *)hint; spot = (char *)hint;
} }
if (spot == NULL) { if (!spot) {
return; return;
} }
@ -3375,7 +3375,7 @@ void SDL_LoadVIDPIDListFromHint(const char *hint, SDL_vidpid_list *list)
entry = (Uint16)SDL_strtol(spot, &spot, 0); entry = (Uint16)SDL_strtol(spot, &spot, 0);
entry <<= 16; entry <<= 16;
spot = SDL_strstr(spot, "0x"); spot = SDL_strstr(spot, "0x");
if (spot == NULL) { if (!spot) {
break; break;
} }
entry |= (Uint16)SDL_strtol(spot, &spot, 0); entry |= (Uint16)SDL_strtol(spot, &spot, 0);
@ -3383,7 +3383,7 @@ void SDL_LoadVIDPIDListFromHint(const char *hint, SDL_vidpid_list *list)
if (list->num_entries == list->max_entries) { if (list->num_entries == list->max_entries) {
int max_entries = list->max_entries + 16; int max_entries = list->max_entries + 16;
Uint32 *entries = (Uint32 *)SDL_realloc(list->entries, max_entries * sizeof(*list->entries)); Uint32 *entries = (Uint32 *)SDL_realloc(list->entries, max_entries * sizeof(*list->entries));
if (entries == NULL) { if (!entries) {
/* Out of memory, go with what we have already */ /* Out of memory, go with what we have already */
break; break;
} }

View File

@ -319,7 +319,7 @@ int Android_AddJoystick(int device_id, const char *name, const char *desc, int v
} }
} }
if (JoystickByDeviceId(device_id) != NULL || name == NULL) { if (JoystickByDeviceId(device_id) != NULL || !name) {
goto done; goto done;
} }
@ -353,7 +353,7 @@ int Android_AddJoystick(int device_id, const char *name, const char *desc, int v
} }
item = (SDL_joylist_item *)SDL_malloc(sizeof(SDL_joylist_item)); item = (SDL_joylist_item *)SDL_malloc(sizeof(SDL_joylist_item));
if (item == NULL) { if (!item) {
goto done; goto done;
} }
@ -361,7 +361,7 @@ int Android_AddJoystick(int device_id, const char *name, const char *desc, int v
item->guid = guid; item->guid = guid;
item->device_id = device_id; item->device_id = device_id;
item->name = SDL_CreateJoystickName(vendor_id, product_id, NULL, name); item->name = SDL_CreateJoystickName(vendor_id, product_id, NULL, name);
if (item->name == NULL) { if (!item->name) {
SDL_free(item); SDL_free(item);
goto done; goto done;
} }
@ -379,7 +379,7 @@ int Android_AddJoystick(int device_id, const char *name, const char *desc, int v
item->naxes = naxes; item->naxes = naxes;
item->nhats = nhats; item->nhats = nhats;
item->device_instance = SDL_GetNextObjectID(); item->device_instance = SDL_GetNextObjectID();
if (SDL_joylist_tail == NULL) { if (!SDL_joylist_tail) {
SDL_joylist = SDL_joylist_tail = item; SDL_joylist = SDL_joylist_tail = item;
} else { } else {
SDL_joylist_tail->next = item; SDL_joylist_tail->next = item;
@ -412,7 +412,7 @@ int Android_RemoveJoystick(int device_id)
SDL_LockJoysticks(); SDL_LockJoysticks();
/* Don't call JoystickByDeviceId here or there'll be an infinite loop! */ /* Don't call JoystickByDeviceId here or there'll be an infinite loop! */
while (item != NULL) { while (item) {
if (item->device_id == device_id) { if (item->device_id == device_id) {
break; break;
} }
@ -420,7 +420,7 @@ int Android_RemoveJoystick(int device_id)
item = item->next; item = item->next;
} }
if (item == NULL) { if (!item) {
goto done; goto done;
} }
@ -428,7 +428,7 @@ int Android_RemoveJoystick(int device_id)
item->joystick->hwdata = NULL; item->joystick->hwdata = NULL;
} }
if (prev != NULL) { if (prev) {
prev->next = item->next; prev->next = item->next;
} else { } else {
SDL_assert(SDL_joylist == item); SDL_assert(SDL_joylist == item);
@ -499,7 +499,7 @@ static SDL_joylist_item *GetJoystickByDevIndex(int device_index)
} }
while (device_index > 0) { while (device_index > 0) {
SDL_assert(item != NULL); SDL_assert(item);
device_index--; device_index--;
item = item->next; item = item->next;
} }
@ -511,7 +511,7 @@ static SDL_joylist_item *JoystickByDeviceId(int device_id)
{ {
SDL_joylist_item *item = SDL_joylist; SDL_joylist_item *item = SDL_joylist;
while (item != NULL) { while (item) {
if (item->device_id == device_id) { if (item->device_id == device_id) {
return item; return item;
} }
@ -521,7 +521,7 @@ static SDL_joylist_item *JoystickByDeviceId(int device_id)
/* Joystick not found, try adding it */ /* Joystick not found, try adding it */
ANDROID_JoystickDetect(); ANDROID_JoystickDetect();
while (item != NULL) { while (item) {
if (item->device_id == device_id) { if (item->device_id == device_id) {
return item; return item;
} }
@ -564,11 +564,11 @@ static int ANDROID_JoystickOpen(SDL_Joystick *joystick, int device_index)
{ {
SDL_joylist_item *item = GetJoystickByDevIndex(device_index); SDL_joylist_item *item = GetJoystickByDevIndex(device_index);
if (item == NULL) { if (!item) {
return SDL_SetError("No such device"); return SDL_SetError("No such device");
} }
if (item->joystick != NULL) { if (item->joystick) {
return SDL_SetError("Joystick already opened"); return SDL_SetError("Joystick already opened");
} }
@ -616,7 +616,7 @@ static void ANDROID_JoystickUpdate(SDL_Joystick *joystick)
{ {
SDL_joylist_item *item = (SDL_joylist_item *)joystick->hwdata; SDL_joylist_item *item = (SDL_joylist_item *)joystick->hwdata;
if (item == NULL) { if (!item) {
return; return;
} }

View File

@ -268,7 +268,7 @@ CreateHwData(const char *path)
hw = (struct joystick_hwdata *) hw = (struct joystick_hwdata *)
SDL_calloc(1, sizeof(struct joystick_hwdata)); SDL_calloc(1, sizeof(struct joystick_hwdata));
if (hw == NULL) { if (!hw) {
close(fd); close(fd);
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
@ -291,7 +291,7 @@ CreateHwData(const char *path)
} }
} }
hw->repdesc = hid_get_report_desc(fd); hw->repdesc = hid_get_report_desc(fd);
if (hw->repdesc == NULL) { if (!hw->repdesc) {
SDL_SetError("%s: USB_GET_REPORT_DESC: %s", path, SDL_SetError("%s: USB_GET_REPORT_DESC: %s", path,
strerror(errno)); strerror(errno));
goto usberr; goto usberr;
@ -318,7 +318,7 @@ CreateHwData(const char *path)
#else #else
hdata = hid_start_parse(hw->repdesc, 1 << hid_input); hdata = hid_start_parse(hw->repdesc, 1 << hid_input);
#endif #endif
if (hdata == NULL) { if (!hdata) {
SDL_SetError("%s: Cannot start HID parser", path); SDL_SetError("%s: Cannot start HID parser", path);
goto usberr; goto usberr;
} }
@ -398,7 +398,7 @@ static int MaybeAddDevice(const char *path)
SDL_joylist_item *item; SDL_joylist_item *item;
struct joystick_hwdata *hw; struct joystick_hwdata *hw;
if (path == NULL) { if (!path) {
return -1; return -1;
} }
@ -407,14 +407,14 @@ static int MaybeAddDevice(const char *path)
} }
/* Check to make sure it's not already in list. */ /* Check to make sure it's not already in list. */
for (item = SDL_joylist; item != NULL; item = item->next) { for (item = SDL_joylist; item; item = item->next) {
if (sb.st_rdev == item->devnum) { if (sb.st_rdev == item->devnum) {
return -1; /* already have this one */ return -1; /* already have this one */
} }
} }
hw = CreateHwData(path); hw = CreateHwData(path);
if (hw == NULL) { if (!hw) {
return -1; return -1;
} }
@ -444,14 +444,14 @@ static int MaybeAddDevice(const char *path)
} }
#endif /* USB_GET_DEVICEINFO */ #endif /* USB_GET_DEVICEINFO */
} }
if (name == NULL) { if (!name) {
name = SDL_strdup(path); name = SDL_strdup(path);
guid = SDL_CreateJoystickGUIDForName(name); guid = SDL_CreateJoystickGUIDForName(name);
} }
FreeHwData(hw); FreeHwData(hw);
item = (SDL_joylist_item *)SDL_calloc(1, sizeof(SDL_joylist_item)); item = (SDL_joylist_item *)SDL_calloc(1, sizeof(SDL_joylist_item));
if (item == NULL) { if (!item) {
SDL_free(name); SDL_free(name);
return -1; return -1;
} }
@ -461,13 +461,13 @@ static int MaybeAddDevice(const char *path)
item->name = name; item->name = name;
item->guid = guid; item->guid = guid;
if ((item->path == NULL) || (item->name == NULL)) { if ((!item->path) || (!item->name)) {
FreeJoylistItem(item); FreeJoylistItem(item);
return -1; return -1;
} }
item->device_instance = SDL_GetNextObjectID(); item->device_instance = SDL_GetNextObjectID();
if (SDL_joylist_tail == NULL) { if (!SDL_joylist_tail) {
SDL_joylist = SDL_joylist_tail = item; SDL_joylist = SDL_joylist_tail = item;
} else { } else {
SDL_joylist_tail->next = item; SDL_joylist_tail->next = item;
@ -526,7 +526,7 @@ static SDL_joylist_item *GetJoystickByDevIndex(int device_index)
} }
while (device_index > 0) { while (device_index > 0) {
SDL_assert(item != NULL); SDL_assert(item);
device_index--; device_index--;
item = item->next; item = item->next;
} }
@ -583,12 +583,12 @@ static int BSD_JoystickOpen(SDL_Joystick *joy, int device_index)
SDL_joylist_item *item = GetJoystickByDevIndex(device_index); SDL_joylist_item *item = GetJoystickByDevIndex(device_index);
struct joystick_hwdata *hw; struct joystick_hwdata *hw;
if (item == NULL) { if (!item) {
return SDL_SetError("No such device"); return SDL_SetError("No such device");
} }
hw = CreateHwData(item->path); hw = CreateHwData(item->path);
if (hw == NULL) { if (!hw) {
return -1; return -1;
} }
@ -664,7 +664,7 @@ static void BSD_JoystickUpdate(SDL_Joystick *joy)
#else #else
hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input); hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input);
#endif #endif
if (hdata == NULL) { if (!hdata) {
/*fprintf(stderr, "%s: Cannot start HID parser\n", joy->hwdata->path);*/ /*fprintf(stderr, "%s: Cannot start HID parser\n", joy->hwdata->path);*/
continue; continue;
} }
@ -793,7 +793,7 @@ static int report_alloc(struct report *r, struct report_desc *rd, int repind)
r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) + r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) +
r->size); r->size);
#endif #endif
if (r->buf == NULL) { if (!r->buf) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
} else { } else {

View File

@ -40,7 +40,7 @@ static recDevice *gpDeviceList = NULL;
void FreeRumbleEffectData(FFEFFECT *effect) void FreeRumbleEffectData(FFEFFECT *effect)
{ {
if (effect == NULL) { if (!effect) {
return; return;
} }
SDL_free(effect->rgdwAxes); SDL_free(effect->rgdwAxes);
@ -56,7 +56,7 @@ FFEFFECT *CreateRumbleEffectData(Sint16 magnitude)
/* Create the effect */ /* Create the effect */
effect = (FFEFFECT *)SDL_calloc(1, sizeof(*effect)); effect = (FFEFFECT *)SDL_calloc(1, sizeof(*effect));
if (effect == NULL) { if (!effect) {
return NULL; return NULL;
} }
effect->dwSize = sizeof(*effect); effect->dwSize = sizeof(*effect);
@ -80,7 +80,7 @@ FFEFFECT *CreateRumbleEffectData(Sint16 magnitude)
effect->dwFlags |= FFEFF_CARTESIAN; effect->dwFlags |= FFEFF_CARTESIAN;
periodic = (FFPERIODIC *)SDL_calloc(1, sizeof(*periodic)); periodic = (FFPERIODIC *)SDL_calloc(1, sizeof(*periodic));
if (periodic == NULL) { if (!periodic) {
FreeRumbleEffectData(effect); FreeRumbleEffectData(effect);
return NULL; return NULL;
} }
@ -506,7 +506,7 @@ static SDL_bool JoystickAlreadyKnown(IOHIDDeviceRef ioHIDDeviceObject)
} }
#endif #endif
for (i = gpDeviceList; i != NULL; i = i->pNext) { for (i = gpDeviceList; i; i = i->pNext) {
if (i->deviceRef == ioHIDDeviceObject) { if (i->deviceRef == ioHIDDeviceObject) {
return SDL_TRUE; return SDL_TRUE;
} }
@ -528,7 +528,7 @@ static void JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender
} }
device = (recDevice *)SDL_calloc(1, sizeof(recDevice)); device = (recDevice *)SDL_calloc(1, sizeof(recDevice));
if (device == NULL) { if (!device) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return; return;
} }
@ -561,13 +561,13 @@ static void JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender
} }
/* Add device to the end of the list */ /* Add device to the end of the list */
if (gpDeviceList == NULL) { if (!gpDeviceList) {
gpDeviceList = device; gpDeviceList = device;
} else { } else {
recDevice *curdevice; recDevice *curdevice;
curdevice = gpDeviceList; curdevice = gpDeviceList;
while (curdevice->pNext != NULL) { while (curdevice->pNext) {
curdevice = curdevice->pNext; curdevice = curdevice->pNext;
} }
curdevice->pNext = device; curdevice->pNext = device;
@ -851,7 +851,7 @@ static int DARWIN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_ru
/* Scale and average the two rumble strengths */ /* Scale and average the two rumble strengths */
Sint16 magnitude = (Sint16)(((low_frequency_rumble / 2) + (high_frequency_rumble / 2)) / 2); Sint16 magnitude = (Sint16)(((low_frequency_rumble / 2) + (high_frequency_rumble / 2)) / 2);
if (device == NULL) { if (!device) {
return SDL_SetError("Rumble failed, device disconnected"); return SDL_SetError("Rumble failed, device disconnected");
} }
@ -892,7 +892,7 @@ static Uint32 DARWIN_JoystickGetCapabilities(SDL_Joystick *joystick)
recDevice *device = joystick->hwdata; recDevice *device = joystick->hwdata;
Uint32 result = 0; Uint32 result = 0;
if (device == NULL) { if (!device) {
return 0; return 0;
} }
@ -926,7 +926,7 @@ static void DARWIN_JoystickUpdate(SDL_Joystick *joystick)
int i, goodRead = SDL_FALSE; int i, goodRead = SDL_FALSE;
Uint64 timestamp = SDL_GetTicksNS(); Uint64 timestamp = SDL_GetTicksNS();
if (device == NULL) { if (!device) {
return; return;
} }

View File

@ -45,7 +45,7 @@ static EM_BOOL Emscripten_JoyStickConnected(int eventType, const EmscriptenGamep
} }
item = (SDL_joylist_item *)SDL_malloc(sizeof(SDL_joylist_item)); item = (SDL_joylist_item *)SDL_malloc(sizeof(SDL_joylist_item));
if (item == NULL) { if (!item) {
return 1; return 1;
} }
@ -53,13 +53,13 @@ static EM_BOOL Emscripten_JoyStickConnected(int eventType, const EmscriptenGamep
item->index = gamepadEvent->index; item->index = gamepadEvent->index;
item->name = SDL_CreateJoystickName(0, 0, NULL, gamepadEvent->id); item->name = SDL_CreateJoystickName(0, 0, NULL, gamepadEvent->id);
if (item->name == NULL) { if (!item->name) {
SDL_free(item); SDL_free(item);
return 1; return 1;
} }
item->mapping = SDL_strdup(gamepadEvent->mapping); item->mapping = SDL_strdup(gamepadEvent->mapping);
if (item->mapping == NULL) { if (!item->mapping) {
SDL_free(item->name); SDL_free(item->name);
SDL_free(item); SDL_free(item);
return 1; return 1;
@ -80,7 +80,7 @@ static EM_BOOL Emscripten_JoyStickConnected(int eventType, const EmscriptenGamep
item->digitalButton[i] = gamepadEvent->digitalButton[i]; item->digitalButton[i] = gamepadEvent->digitalButton[i];
} }
if (SDL_joylist_tail == NULL) { if (!SDL_joylist_tail) {
SDL_joylist = SDL_joylist_tail = item; SDL_joylist = SDL_joylist_tail = item;
} else { } else {
SDL_joylist_tail->next = item; SDL_joylist_tail->next = item;
@ -106,7 +106,7 @@ static EM_BOOL Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGa
SDL_joylist_item *item = SDL_joylist; SDL_joylist_item *item = SDL_joylist;
SDL_joylist_item *prev = NULL; SDL_joylist_item *prev = NULL;
while (item != NULL) { while (item) {
if (item->index == gamepadEvent->index) { if (item->index == gamepadEvent->index) {
break; break;
} }
@ -114,7 +114,7 @@ static EM_BOOL Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGa
item = item->next; item = item->next;
} }
if (item == NULL) { if (!item) {
return 1; return 1;
} }
@ -122,7 +122,7 @@ static EM_BOOL Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGa
item->joystick->hwdata = NULL; item->joystick->hwdata = NULL;
} }
if (prev != NULL) { if (prev) {
prev->next = item->next; prev->next = item->next;
} else { } else {
SDL_assert(SDL_joylist == item); SDL_assert(SDL_joylist == item);
@ -240,7 +240,7 @@ static SDL_joylist_item *JoystickByIndex(int index)
return NULL; return NULL;
} }
while (item != NULL) { while (item) {
if (item->index == index) { if (item->index == index) {
break; break;
} }
@ -292,11 +292,11 @@ static int EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index)
{ {
SDL_joylist_item *item = JoystickByDeviceIndex(device_index); SDL_joylist_item *item = JoystickByDeviceIndex(device_index);
if (item == NULL) { if (!item) {
return SDL_SetError("No such device"); return SDL_SetError("No such device");
} }
if (item->joystick != NULL) { if (item->joystick) {
return SDL_SetError("Joystick already opened"); return SDL_SetError("Joystick already opened");
} }

View File

@ -135,7 +135,7 @@ static SDL_bool HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
#endif #endif
ctx = (SDL_DriverGameCube_Context *)SDL_calloc(1, sizeof(*ctx)); ctx = (SDL_DriverGameCube_Context *)SDL_calloc(1, sizeof(*ctx));
if (ctx == NULL) { if (!ctx) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;
} }
@ -245,7 +245,7 @@ static void HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device
} }
joystick = SDL_GetJoystickFromInstanceID(ctx->joysticks[i]); joystick = SDL_GetJoystickFromInstanceID(ctx->joysticks[i]);
if (joystick == NULL) { if (!joystick) {
/* Hasn't been opened yet, skip */ /* Hasn't been opened yet, skip */
return; return;
} }
@ -322,7 +322,7 @@ static void HIDAPI_DriverGameCube_HandleNintendoPacket(SDL_HIDAPI_Device *device
joystick = SDL_GetJoystickFromInstanceID(ctx->joysticks[i]); joystick = SDL_GetJoystickFromInstanceID(ctx->joysticks[i]);
/* Hasn't been opened yet, skip */ /* Hasn't been opened yet, skip */
if (joystick == NULL) { if (!joystick) {
continue; continue;
} }
} else { } else {

View File

@ -72,7 +72,7 @@ static SDL_bool HIDAPI_DriverLuna_InitDevice(SDL_HIDAPI_Device *device)
SDL_DriverLuna_Context *ctx; SDL_DriverLuna_Context *ctx;
ctx = (SDL_DriverLuna_Context *)SDL_calloc(1, sizeof(*ctx)); ctx = (SDL_DriverLuna_Context *)SDL_calloc(1, sizeof(*ctx));
if (ctx == NULL) { if (!ctx) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;
} }
@ -393,7 +393,7 @@ static SDL_bool HIDAPI_DriverLuna_UpdateDevice(SDL_HIDAPI_Device *device)
#ifdef DEBUG_LUNA_PROTOCOL #ifdef DEBUG_LUNA_PROTOCOL
HIDAPI_DumpPacket("Amazon Luna packet: size = %d", data, size); HIDAPI_DumpPacket("Amazon Luna packet: size = %d", data, size);
#endif #endif
if (joystick == NULL) { if (!joystick) {
continue; continue;
} }

View File

@ -134,7 +134,7 @@ static SDL_bool HIDAPI_DriverPS3_InitDevice(SDL_HIDAPI_Device *device)
} }
ctx = (SDL_DriverPS3_Context *)SDL_calloc(1, sizeof(*ctx)); ctx = (SDL_DriverPS3_Context *)SDL_calloc(1, sizeof(*ctx));
if (ctx == NULL) { if (!ctx) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;
} }
@ -215,7 +215,7 @@ static void HIDAPI_DriverPS3_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL
{ {
SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context; SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context;
if (ctx == NULL) { if (!ctx) {
return; return;
} }
@ -491,7 +491,7 @@ static SDL_bool HIDAPI_DriverPS3_UpdateDevice(SDL_HIDAPI_Device *device)
#ifdef DEBUG_PS3_PROTOCOL #ifdef DEBUG_PS3_PROTOCOL
HIDAPI_DumpPacket("PS3 packet: size = %d", data, size); HIDAPI_DumpPacket("PS3 packet: size = %d", data, size);
#endif #endif
if (joystick == NULL) { if (!joystick) {
continue; continue;
} }
@ -604,7 +604,7 @@ static SDL_bool HIDAPI_DriverPS3ThirdParty_InitDevice(SDL_HIDAPI_Device *device)
SDL_DriverPS3_Context *ctx; SDL_DriverPS3_Context *ctx;
ctx = (SDL_DriverPS3_Context *)SDL_calloc(1, sizeof(*ctx)); ctx = (SDL_DriverPS3_Context *)SDL_calloc(1, sizeof(*ctx));
if (ctx == NULL) { if (!ctx) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;
} }
@ -932,7 +932,7 @@ static SDL_bool HIDAPI_DriverPS3ThirdParty_UpdateDevice(SDL_HIDAPI_Device *devic
#ifdef DEBUG_PS3_PROTOCOL #ifdef DEBUG_PS3_PROTOCOL
HIDAPI_DumpPacket("PS3 packet: size = %d", data, size); HIDAPI_DumpPacket("PS3 packet: size = %d", data, size);
#endif #endif
if (joystick == NULL) { if (!joystick) {
continue; continue;
} }

View File

@ -275,7 +275,7 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMEPAD; SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMEPAD;
ctx = (SDL_DriverPS4_Context *)SDL_calloc(1, sizeof(*ctx)); ctx = (SDL_DriverPS4_Context *)SDL_calloc(1, sizeof(*ctx));
if (ctx == NULL) { if (!ctx) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;
} }
@ -1207,7 +1207,7 @@ static SDL_bool HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
++packet_count; ++packet_count;
ctx->last_packet = now; ctx->last_packet = now;
if (joystick == NULL) { if (!joystick) {
continue; continue;
} }

View File

@ -373,7 +373,7 @@ static SDL_bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMEPAD; SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMEPAD;
ctx = (SDL_DriverPS5_Context *)SDL_calloc(1, sizeof(*ctx)); ctx = (SDL_DriverPS5_Context *)SDL_calloc(1, sizeof(*ctx));
if (ctx == NULL) { if (!ctx) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;
} }
@ -1476,7 +1476,7 @@ static SDL_bool HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
++packet_count; ++packet_count;
ctx->last_packet = now; ctx->last_packet = now;
if (joystick == NULL) { if (!joystick) {
continue; continue;
} }

View File

@ -214,7 +214,7 @@ int SDL_HIDAPI_SendRumbleWithCallbackAndUnlock(SDL_HIDAPI_Device *device, const
} }
request = (SDL_HIDAPI_RumbleRequest *)SDL_calloc(1, sizeof(*request)); request = (SDL_HIDAPI_RumbleRequest *)SDL_calloc(1, sizeof(*request));
if (request == NULL) { if (!request) {
SDL_HIDAPI_UnlockRumble(); SDL_HIDAPI_UnlockRumble();
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }

View File

@ -114,7 +114,7 @@ static SDL_bool HIDAPI_DriverShield_InitDevice(SDL_HIDAPI_Device *device)
SDL_DriverShield_Context *ctx; SDL_DriverShield_Context *ctx;
ctx = (SDL_DriverShield_Context *)SDL_calloc(1, sizeof(*ctx)); ctx = (SDL_DriverShield_Context *)SDL_calloc(1, sizeof(*ctx));
if (ctx == NULL) { if (!ctx) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;
} }
@ -489,7 +489,7 @@ static SDL_bool HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device)
/* Byte 0 is HID report ID */ /* Byte 0 is HID report ID */
switch (data[0]) { switch (data[0]) {
case k_ShieldReportIdControllerState: case k_ShieldReportIdControllerState:
if (joystick == NULL) { if (!joystick) {
break; break;
} }
if (size == 16) { if (size == 16) {
@ -499,7 +499,7 @@ static SDL_bool HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device)
} }
break; break;
case k_ShieldReportIdControllerTouch: case k_ShieldReportIdControllerTouch:
if (joystick == NULL) { if (!joystick) {
break; break;
} }
HIDAPI_DriverShield_HandleTouchPacketV103(joystick, ctx, data, size); HIDAPI_DriverShield_HandleTouchPacketV103(joystick, ctx, data, size);

View File

@ -69,7 +69,7 @@ static SDL_bool HIDAPI_DriverStadia_InitDevice(SDL_HIDAPI_Device *device)
SDL_DriverStadia_Context *ctx; SDL_DriverStadia_Context *ctx;
ctx = (SDL_DriverStadia_Context *)SDL_calloc(1, sizeof(*ctx)); ctx = (SDL_DriverStadia_Context *)SDL_calloc(1, sizeof(*ctx));
if (ctx == NULL) { if (!ctx) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;
} }
@ -285,7 +285,7 @@ static SDL_bool HIDAPI_DriverStadia_UpdateDevice(SDL_HIDAPI_Device *device)
#ifdef DEBUG_STADIA_PROTOCOL #ifdef DEBUG_STADIA_PROTOCOL
HIDAPI_DumpPacket("Google Stadia packet: size = %d", data, size); HIDAPI_DumpPacket("Google Stadia packet: size = %d", data, size);
#endif #endif
if (joystick == NULL) { if (!joystick) {
continue; continue;
} }

View File

@ -973,7 +973,7 @@ static SDL_bool HIDAPI_DriverSteam_InitDevice(SDL_HIDAPI_Device *device)
SDL_DriverSteam_Context *ctx; SDL_DriverSteam_Context *ctx;
ctx = (SDL_DriverSteam_Context *)SDL_calloc(1, sizeof(*ctx)); ctx = (SDL_DriverSteam_Context *)SDL_calloc(1, sizeof(*ctx));
if (ctx == NULL) { if (!ctx) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;
} }
@ -1105,7 +1105,7 @@ static SDL_bool HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
break; break;
} }
if (joystick == NULL) { if (!joystick) {
continue; continue;
} }

Some files were not shown because too many files have changed in this diff Show More