Pointer as bool (libsdl-org#7214)

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

View File

@@ -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.");
}