mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-04 17:06:25 +00:00
Pointer as bool (libsdl-org#7214)
This commit is contained in:
@@ -188,7 +188,7 @@ static SDL_hapticlist_item *HapticByDevIndex(int device_index)
|
||||
}
|
||||
|
||||
while (device_index > 0) {
|
||||
SDL_assert(item != NULL);
|
||||
SDL_assert(item);
|
||||
--device_index;
|
||||
item = item->next;
|
||||
}
|
||||
@@ -199,7 +199,7 @@ static SDL_hapticlist_item *HapticByDevIndex(int device_index)
|
||||
#ifdef SDL_USE_LIBUDEV
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ static int MaybeAddDevice(const char *path)
|
||||
int success;
|
||||
SDL_hapticlist_item *item;
|
||||
|
||||
if (path == NULL) {
|
||||
if (!path) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ static int MaybeAddDevice(const char *path)
|
||||
}
|
||||
|
||||
/* 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) {
|
||||
return -1; /* duplicate. */
|
||||
}
|
||||
@@ -259,12 +259,12 @@ static int MaybeAddDevice(const char *path)
|
||||
}
|
||||
|
||||
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
item->fname = SDL_strdup(path);
|
||||
if (item->fname == NULL) {
|
||||
if (!item->fname) {
|
||||
SDL_free(item);
|
||||
return -1;
|
||||
}
|
||||
@@ -272,7 +272,7 @@ static int MaybeAddDevice(const char *path)
|
||||
item->dev_num = sb.st_rdev;
|
||||
|
||||
/* TODO: should we add instance IDs? */
|
||||
if (SDL_hapticlist_tail == NULL) {
|
||||
if (!SDL_hapticlist_tail) {
|
||||
SDL_hapticlist = SDL_hapticlist_tail = item;
|
||||
} else {
|
||||
SDL_hapticlist_tail->next = item;
|
||||
@@ -292,16 +292,16 @@ static int MaybeRemoveDevice(const char *path)
|
||||
SDL_hapticlist_item *item;
|
||||
SDL_hapticlist_item *prev = NULL;
|
||||
|
||||
if (path == NULL) {
|
||||
if (!path) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (item = SDL_hapticlist; item != NULL; item = item->next) {
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
/* found it, remove it. */
|
||||
if (SDL_strcmp(path, item->fname) == 0) {
|
||||
const int retval = item->haptic ? item->haptic->index : -1;
|
||||
|
||||
if (prev != NULL) {
|
||||
if (prev) {
|
||||
prev->next = item->next;
|
||||
} else {
|
||||
SDL_assert(SDL_hapticlist == item);
|
||||
@@ -358,7 +358,7 @@ const char *SDL_SYS_HapticName(int index)
|
||||
if (fd >= 0) {
|
||||
|
||||
name = SDL_SYS_HapticNameFromFD(fd);
|
||||
if (name == NULL) {
|
||||
if (!name) {
|
||||
/* No name found, return device character device */
|
||||
name = item->fname;
|
||||
}
|
||||
@@ -376,7 +376,7 @@ static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd)
|
||||
/* Allocate the hwdata */
|
||||
haptic->hwdata = (struct haptic_hwdata *)
|
||||
SDL_malloc(sizeof(*haptic->hwdata));
|
||||
if (haptic->hwdata == NULL) {
|
||||
if (!haptic->hwdata) {
|
||||
SDL_OutOfMemory();
|
||||
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->effects = (struct haptic_effect *)
|
||||
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
|
||||
if (haptic->effects == NULL) {
|
||||
if (!haptic->effects) {
|
||||
SDL_OutOfMemory();
|
||||
goto open_err;
|
||||
}
|
||||
@@ -409,7 +409,7 @@ static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd)
|
||||
/* Error handling */
|
||||
open_err:
|
||||
close(fd);
|
||||
if (haptic->hwdata != NULL) {
|
||||
if (haptic->hwdata) {
|
||||
SDL_free(haptic->hwdata);
|
||||
haptic->hwdata = NULL;
|
||||
}
|
||||
@@ -904,7 +904,7 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
/* Allocate the hardware effect */
|
||||
effect->hweffect = (struct haptic_hweffect *)
|
||||
SDL_malloc(sizeof(struct haptic_hweffect));
|
||||
if (effect->hweffect == NULL) {
|
||||
if (!effect->hweffect) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user