mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-06 18:06:26 +00:00
Pointer as bool (libsdl-org#7214)
This commit is contained in:
@@ -55,7 +55,7 @@ static int ValidHaptic(SDL_Haptic *haptic)
|
||||
SDL_Haptic *hapticlist;
|
||||
|
||||
valid = 0;
|
||||
if (haptic != NULL) {
|
||||
if (haptic) {
|
||||
hapticlist = SDL_haptics;
|
||||
while (hapticlist) {
|
||||
if (hapticlist == haptic) {
|
||||
@@ -124,7 +124,7 @@ SDL_Haptic *SDL_HapticOpen(int device_index)
|
||||
|
||||
/* Create the haptic device */
|
||||
haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic));
|
||||
if (haptic == NULL) {
|
||||
if (!haptic) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -296,7 +296,7 @@ SDL_Haptic *SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
|
||||
|
||||
/* Create the haptic device */
|
||||
haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic));
|
||||
if (haptic == NULL) {
|
||||
if (!haptic) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_UnlockJoysticks();
|
||||
return NULL;
|
||||
@@ -609,7 +609,7 @@ int SDL_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
|
||||
/* We use the envvar to get the maximum gain. */
|
||||
env = SDL_getenv("SDL_HAPTIC_GAIN_MAX");
|
||||
if (env != NULL) {
|
||||
if (env) {
|
||||
max_gain = SDL_atoi(env);
|
||||
|
||||
/* Check for sanity. */
|
||||
|
@@ -59,7 +59,7 @@ static SDL_hapticlist_item *HapticByOrder(int index)
|
||||
return NULL;
|
||||
}
|
||||
while (index > 0) {
|
||||
SDL_assert(item != NULL);
|
||||
SDL_assert(item);
|
||||
--index;
|
||||
item = item->next;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ static SDL_hapticlist_item *HapticByOrder(int index)
|
||||
static SDL_hapticlist_item *HapticByDevId(int device_id)
|
||||
{
|
||||
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) {
|
||||
/*SDL_Log("=+=+=+=+=+= HapticByDevId id [%d]", device_id);*/
|
||||
return item;
|
||||
@@ -81,7 +81,7 @@ static SDL_hapticlist_item *HapticByDevId(int device_id)
|
||||
const char *SDL_SYS_HapticName(int index)
|
||||
{
|
||||
SDL_hapticlist_item *item = HapticByOrder(index);
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
SDL_SetError("No such device");
|
||||
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)
|
||||
{
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
SDL_SetError("No such device");
|
||||
return NULL;
|
||||
}
|
||||
if (item->haptic != NULL) {
|
||||
if (item->haptic) {
|
||||
SDL_SetError("Haptic already opened");
|
||||
return NULL;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ static SDL_hapticlist_item *OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *
|
||||
haptic->neffects = 1;
|
||||
haptic->nplaying = haptic->neffects;
|
||||
haptic->effects = (struct haptic_effect *)SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
|
||||
if (haptic->effects == NULL) {
|
||||
if (!haptic->effects) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
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)
|
||||
@@ -246,18 +246,18 @@ int Android_AddHaptic(int device_id, const char *name)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
item->device_id = device_id;
|
||||
item->name = SDL_strdup(name);
|
||||
if (item->name == NULL) {
|
||||
if (!item->name) {
|
||||
SDL_free(item);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (SDL_hapticlist_tail == NULL) {
|
||||
if (!SDL_hapticlist_tail) {
|
||||
SDL_hapticlist = SDL_hapticlist_tail = item;
|
||||
} else {
|
||||
SDL_hapticlist_tail->next = item;
|
||||
@@ -273,12 +273,12 @@ int Android_RemoveHaptic(int device_id)
|
||||
SDL_hapticlist_item *item;
|
||||
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. */
|
||||
if (device_id == item->device_id) {
|
||||
const int retval = item->haptic ? item->haptic->index : -1;
|
||||
|
||||
if (prev != NULL) {
|
||||
if (prev) {
|
||||
prev->next = item->next;
|
||||
} else {
|
||||
SDL_assert(SDL_hapticlist == item);
|
||||
|
@@ -154,7 +154,7 @@ int SDL_SYS_HapticInit(void)
|
||||
|
||||
/* Get HID devices. */
|
||||
match = IOServiceMatching(kIOHIDDeviceKey);
|
||||
if (match == NULL) {
|
||||
if (!match) {
|
||||
return SDL_SetError("Haptic: Failed to get IOServiceMatching.");
|
||||
}
|
||||
|
||||
@@ -193,7 +193,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;
|
||||
}
|
||||
@@ -226,7 +226,7 @@ int MacHaptic_MaybeAddDevice(io_object_t device)
|
||||
}
|
||||
|
||||
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
return SDL_SetError("Could not allocate haptic storage");
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ int MacHaptic_MaybeAddDevice(io_object_t device)
|
||||
CFRelease(hidProperties);
|
||||
}
|
||||
|
||||
if (SDL_hapticlist_tail == NULL) {
|
||||
if (!SDL_hapticlist_tail) {
|
||||
SDL_hapticlist = SDL_hapticlist_tail = item;
|
||||
} else {
|
||||
SDL_hapticlist_tail->next = item;
|
||||
@@ -284,12 +284,12 @@ int MacHaptic_MaybeRemoveDevice(io_object_t device)
|
||||
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. */
|
||||
if (IOObjectIsEqualTo((io_object_t)item->dev, device)) {
|
||||
const int retval = item->haptic ? item->haptic->index : -1;
|
||||
|
||||
if (prev != NULL) {
|
||||
if (prev) {
|
||||
prev->next = item->next;
|
||||
} else {
|
||||
SDL_assert(SDL_hapticlist == item);
|
||||
@@ -475,7 +475,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
|
||||
/* Allocate the hwdata */
|
||||
haptic->hwdata = (struct haptic_hwdata *)
|
||||
SDL_malloc(sizeof(*haptic->hwdata));
|
||||
if (haptic->hwdata == NULL) {
|
||||
if (!haptic->hwdata) {
|
||||
SDL_OutOfMemory();
|
||||
goto creat_err;
|
||||
}
|
||||
@@ -512,7 +512,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
|
||||
/* Allocate effects memory. */
|
||||
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;
|
||||
}
|
||||
@@ -526,7 +526,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
|
||||
open_err:
|
||||
FFReleaseDevice(haptic->hwdata->device);
|
||||
creat_err:
|
||||
if (haptic->hwdata != NULL) {
|
||||
if (haptic->hwdata) {
|
||||
SDL_free(haptic->hwdata);
|
||||
haptic->hwdata = NULL;
|
||||
}
|
||||
@@ -699,7 +699,7 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, SDL_HapticDirection *dir, int
|
||||
|
||||
/* Has axes. */
|
||||
rglDir = SDL_malloc(sizeof(LONG) * naxes);
|
||||
if (rglDir == NULL) {
|
||||
if (!rglDir) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
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 = SDL_malloc(sizeof(FFENVELOPE));
|
||||
if (envelope == NULL) {
|
||||
if (!envelope) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
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) {
|
||||
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
|
||||
if (axes == NULL) {
|
||||
if (!axes) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
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:
|
||||
hap_constant = &src->constant;
|
||||
constant = SDL_malloc(sizeof(FFCONSTANTFORCE));
|
||||
if (constant == NULL) {
|
||||
if (!constant) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
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:
|
||||
hap_periodic = &src->periodic;
|
||||
periodic = SDL_malloc(sizeof(FFPERIODIC));
|
||||
if (periodic == NULL) {
|
||||
if (!periodic) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
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;
|
||||
if (dest->cAxes > 0) {
|
||||
condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
|
||||
if (condition == NULL) {
|
||||
if (!condition) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
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:
|
||||
hap_ramp = &src->ramp;
|
||||
ramp = SDL_malloc(sizeof(FFRAMPFORCE));
|
||||
if (ramp == NULL) {
|
||||
if (!ramp) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
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:
|
||||
hap_custom = &src->custom;
|
||||
custom = SDL_malloc(sizeof(FFCUSTOMFORCE));
|
||||
if (custom == NULL) {
|
||||
if (!custom) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE));
|
||||
@@ -1033,7 +1033,7 @@ static void SDL_SYS_HapticFreeFFEFFECT(FFEFFECT *effect, int type)
|
||||
effect->lpEnvelope = NULL;
|
||||
SDL_free(effect->rgdwAxes);
|
||||
effect->rgdwAxes = NULL;
|
||||
if (effect->lpvTypeSpecificParams != NULL) {
|
||||
if (effect->lpvTypeSpecificParams) {
|
||||
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
|
||||
custom = (FFCUSTOMFORCE *)effect->lpvTypeSpecificParams;
|
||||
SDL_free(custom->rglForceData);
|
||||
@@ -1108,14 +1108,14 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
/* Alloc the effect. */
|
||||
effect->hweffect = (struct haptic_hweffect *)
|
||||
SDL_malloc(sizeof(struct haptic_hweffect));
|
||||
if (effect->hweffect == NULL) {
|
||||
if (!effect->hweffect) {
|
||||
SDL_OutOfMemory();
|
||||
goto err_hweffect;
|
||||
}
|
||||
|
||||
/* Get the type. */
|
||||
type = SDL_SYS_HapticEffectType(base->type);
|
||||
if (type == NULL) {
|
||||
if (!type) {
|
||||
goto err_hweffect;
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
@@ -92,7 +92,7 @@ int SDL_DINPUT_HapticInit(void)
|
||||
|
||||
/* Because we used CoCreateInstance, we need to Initialize it, first. */
|
||||
instance = GetModuleHandle(NULL);
|
||||
if (instance == NULL) {
|
||||
if (!instance) {
|
||||
SDL_SYS_HapticQuit();
|
||||
return SDL_SetError("GetModuleHandle() failed with error code %lu.",
|
||||
GetLastError());
|
||||
@@ -133,7 +133,7 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
|
||||
DIDEVCAPS capabilities;
|
||||
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. */
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
|
||||
}
|
||||
|
||||
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -188,11 +188,11 @@ int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance)
|
||||
SDL_hapticlist_item *item;
|
||||
SDL_hapticlist_item *prev = NULL;
|
||||
|
||||
if (dinput == NULL) {
|
||||
if (!dinput) {
|
||||
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) {
|
||||
/* found it, remove it. */
|
||||
return SDL_SYS_RemoveHapticDevice(prev, item);
|
||||
@@ -287,7 +287,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
|
||||
/* Allocate the hwdata */
|
||||
haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata));
|
||||
if (haptic->hwdata == NULL) {
|
||||
if (!haptic->hwdata) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
|
||||
@@ -401,7 +401,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
/* Prepare effects memory. */
|
||||
haptic->effects = (struct haptic_effect *)
|
||||
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
|
||||
if (haptic->effects == NULL) {
|
||||
if (!haptic->effects) {
|
||||
SDL_OutOfMemory();
|
||||
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. */
|
||||
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)) {
|
||||
haptic->index = index;
|
||||
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. */
|
||||
rglDir = SDL_malloc(sizeof(LONG) * naxes);
|
||||
if (rglDir == NULL) {
|
||||
if (!rglDir) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
|
||||
@@ -614,7 +614,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
|
||||
/* Envelope. */
|
||||
envelope = SDL_malloc(sizeof(DIENVELOPE));
|
||||
if (envelope == NULL) {
|
||||
if (!envelope) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(envelope, 0, sizeof(DIENVELOPE));
|
||||
@@ -629,7 +629,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
}
|
||||
if (dest->cAxes > 0) {
|
||||
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
|
||||
if (axes == NULL) {
|
||||
if (!axes) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
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:
|
||||
hap_constant = &src->constant;
|
||||
constant = SDL_malloc(sizeof(DICONSTANTFORCE));
|
||||
if (constant == NULL) {
|
||||
if (!constant) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(constant, 0, sizeof(DICONSTANTFORCE));
|
||||
@@ -689,7 +689,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
case SDL_HAPTIC_SAWTOOTHDOWN:
|
||||
hap_periodic = &src->periodic;
|
||||
periodic = SDL_malloc(sizeof(DIPERIODIC));
|
||||
if (periodic == NULL) {
|
||||
if (!periodic) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(periodic, 0, sizeof(DIPERIODIC));
|
||||
@@ -733,7 +733,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
case SDL_HAPTIC_FRICTION:
|
||||
hap_condition = &src->condition;
|
||||
condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes);
|
||||
if (condition == NULL) {
|
||||
if (!condition) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(condition, 0, sizeof(DICONDITION));
|
||||
@@ -774,7 +774,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
case SDL_HAPTIC_RAMP:
|
||||
hap_ramp = &src->ramp;
|
||||
ramp = SDL_malloc(sizeof(DIRAMPFORCE));
|
||||
if (ramp == NULL) {
|
||||
if (!ramp) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(ramp, 0, sizeof(DIRAMPFORCE));
|
||||
@@ -812,7 +812,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
case SDL_HAPTIC_CUSTOM:
|
||||
hap_custom = &src->custom;
|
||||
custom = SDL_malloc(sizeof(DICUSTOMFORCE));
|
||||
if (custom == NULL) {
|
||||
if (!custom) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(custom, 0, sizeof(DICUSTOMFORCE));
|
||||
@@ -871,7 +871,7 @@ static void SDL_SYS_HapticFreeDIEFFECT(DIEFFECT *effect, int type)
|
||||
effect->lpEnvelope = NULL;
|
||||
SDL_free(effect->rgdwAxes);
|
||||
effect->rgdwAxes = NULL;
|
||||
if (effect->lpvTypeSpecificParams != NULL) {
|
||||
if (effect->lpvTypeSpecificParams) {
|
||||
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
|
||||
custom = (DICUSTOMFORCE *)effect->lpvTypeSpecificParams;
|
||||
SDL_free(custom->rglForceData);
|
||||
@@ -937,7 +937,7 @@ int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
HRESULT ret;
|
||||
REFGUID type = SDL_SYS_HapticEffectType(base);
|
||||
|
||||
if (type == NULL) {
|
||||
if (!type) {
|
||||
return SDL_SetError("Haptic: Unknown effect type.");
|
||||
}
|
||||
|
||||
|
@@ -75,7 +75,7 @@ int SDL_SYS_HapticInit(void)
|
||||
|
||||
int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item)
|
||||
{
|
||||
if (SDL_hapticlist_tail == NULL) {
|
||||
if (!SDL_hapticlist_tail) {
|
||||
SDL_hapticlist = SDL_hapticlist_tail = item;
|
||||
} else {
|
||||
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)
|
||||
{
|
||||
const int retval = item->haptic ? item->haptic->index : -1;
|
||||
if (prev != NULL) {
|
||||
if (prev) {
|
||||
prev->next = item->next;
|
||||
} else {
|
||||
SDL_assert(SDL_hapticlist == item);
|
||||
@@ -120,7 +120,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;
|
||||
}
|
||||
@@ -159,7 +159,7 @@ int SDL_SYS_HapticMouse(void)
|
||||
int index = 0;
|
||||
|
||||
/* 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) {
|
||||
return index;
|
||||
}
|
||||
@@ -293,7 +293,7 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
/* Alloc the effect. */
|
||||
effect->hweffect = (struct haptic_hweffect *)
|
||||
SDL_malloc(sizeof(struct haptic_hweffect));
|
||||
if (effect->hweffect == NULL) {
|
||||
if (!effect->hweffect) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
}
|
||||
|
@@ -79,7 +79,7 @@ int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
|
||||
}
|
||||
|
||||
item = (SDL_hapticlist_item *)SDL_malloc(sizeof(SDL_hapticlist_item));
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ int SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid)
|
||||
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) {
|
||||
/* found it, remove it. */
|
||||
return SDL_SYS_RemoveHapticDevice(prev, item);
|
||||
@@ -173,7 +173,7 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us
|
||||
/* Prepare effects memory. */
|
||||
haptic->effects = (struct haptic_effect *)
|
||||
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
|
||||
if (haptic->effects == NULL) {
|
||||
if (!haptic->effects) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
/* Clear the memory */
|
||||
@@ -181,7 +181,7 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us
|
||||
sizeof(struct haptic_effect) * haptic->neffects);
|
||||
|
||||
haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata));
|
||||
if (haptic->hwdata == NULL) {
|
||||
if (!haptic->hwdata) {
|
||||
SDL_free(haptic->effects);
|
||||
haptic->effects = NULL;
|
||||
return SDL_OutOfMemory();
|
||||
@@ -192,7 +192,7 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us
|
||||
haptic->hwdata->userid = userid;
|
||||
|
||||
haptic->hwdata->mutex = SDL_CreateMutex();
|
||||
if (haptic->hwdata->mutex == NULL) {
|
||||
if (!haptic->hwdata->mutex) {
|
||||
SDL_free(haptic->effects);
|
||||
SDL_free(haptic->hwdata);
|
||||
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);
|
||||
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_free(haptic->effects);
|
||||
SDL_free(haptic->hwdata);
|
||||
@@ -229,7 +229,7 @@ int SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick
|
||||
Uint8 index = 0;
|
||||
|
||||
/* 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) {
|
||||
haptic->index = index;
|
||||
return SDL_XINPUT_HapticOpenFromUserIndex(haptic, joystick->hwdata->userid);
|
||||
|
Reference in New Issue
Block a user