Check standard error code return values as < 0 instead of == -1

This commit is contained in:
Sam Lantinga
2024-08-22 06:53:25 -07:00
parent 46d9066a69
commit 037541a0e0
29 changed files with 59 additions and 59 deletions

View File

@@ -1723,7 +1723,7 @@ SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSp
SDL_SetError("Device was already lost and can't accept new opens");
} else if ((logdev = (SDL_LogicalAudioDevice *) SDL_calloc(1, sizeof (SDL_LogicalAudioDevice))) == NULL) {
/* SDL_calloc already called SDL_OutOfMemory */
} else if (OpenPhysicalAudioDevice(device, spec) == -1) { // if this is the first thing using this physical device, open at the OS level if necessary...
} else if (OpenPhysicalAudioDevice(device, spec) < 0) { // if this is the first thing using this physical device, open at the OS level if necessary...
SDL_free(logdev);
} else {
RefPhysicalAudioDevice(device); // unref'd on successful SDL_CloseAudioDevice
@@ -2267,7 +2267,7 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)
if (needs_migration) {
// New default physical device not been opened yet? Open at the OS level...
if (OpenPhysicalAudioDevice(new_default_device, &spec) == -1) {
if (OpenPhysicalAudioDevice(new_default_device, &spec) < 0) {
needs_migration = SDL_FALSE; // uhoh, just leave everything on the old default, nothing to be done.
}
}

View File

@@ -383,7 +383,7 @@ static int UpdateAudioStreamInputSpec(SDL_AudioStream *stream, const SDL_AudioSp
return 0;
}
if (SDL_ResetAudioQueueHistory(stream->queue, SDL_GetResamplerHistoryFrames()) != 0) {
if (SDL_ResetAudioQueueHistory(stream->queue, SDL_GetResamplerHistoryFrames()) < 0) {
return -1;
}
@@ -428,7 +428,7 @@ SDL_AudioStream *SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_
OnAudioStreamCreated(retval);
if (SDL_SetAudioStreamFormat(retval, src_spec, dst_spec) == -1) {
if (SDL_SetAudioStreamFormat(retval, src_spec, dst_spec) < 0) {
SDL_DestroyAudioStream(retval);
return NULL;
}
@@ -1338,7 +1338,7 @@ int SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data
}
}
if (retval == -1) {
if (retval < 0) {
SDL_free(dst);
} else {
*dst_data = dst;

View File

@@ -703,14 +703,14 @@ static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
/* Initialize decoder with the values from the block header. */
result = MS_ADPCM_DecodeBlockHeader(&state);
if (result == -1) {
if (result < 0) {
SDL_free(state.output.data);
return -1;
}
/* Decode the block data. It stores the samples directly in the output. */
result = MS_ADPCM_DecodeBlockData(&state);
if (result == -1) {
if (result < 0) {
/* Unexpected end. Stop decoding and return partial data if necessary. */
if (file->trunchint == TruncVeryStrict || file->trunchint == TruncStrict) {
SDL_free(state.output.data);
@@ -1105,7 +1105,7 @@ static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len
result = IMA_ADPCM_DecodeBlockData(&state);
}
if (result == -1) {
if (result < 0) {
/* Unexpected end. Stop decoding and return partial data if necessary. */
if (file->trunchint == TruncVeryStrict || file->trunchint == TruncStrict) {
SDL_free(state.output.data);
@@ -1860,7 +1860,7 @@ static int WaveLoad(SDL_IOStream *src, WaveFile *file, SDL_AudioSpec *spec, Uint
}
result = WaveNextChunk(src, chunk);
if (result == -1) {
if (result < 0) {
/* Unexpected EOF. Corrupt file or I/O issues. */
if (file->trunchint == TruncVeryStrict) {
return SDL_SetError("Unexpected end of WAVE file");
@@ -1985,7 +1985,7 @@ static int WaveLoad(SDL_IOStream *src, WaveFile *file, SDL_AudioSpec *spec, Uint
if (chunk->length > 0) {
result = WaveReadChunkData(src, chunk);
if (result == -1) {
if (result < 0) {
return -1;
} else if (result == -2) {
return SDL_SetError("Could not seek data of WAVE data chunk");

View File

@@ -157,7 +157,7 @@ int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, in
static int ManagementThreadPrepare(void)
{
if (WASAPI_PlatformInit() == -1) {
if (WASAPI_PlatformInit() < 0) {
return -1;
}
@@ -402,7 +402,7 @@ static SDL_bool RecoverWasapiDevice(SDL_AudioDevice *device)
ResetWasapiDevice(device); // dump the lost device's handles.
// This handles a non-default device that simply had its format changed in the Windows Control Panel.
if (ActivateWasapiDevice(device) == -1) {
if (ActivateWasapiDevice(device) < 0) {
WASAPI_DisconnectDevice(device);
return SDL_FALSE;
}

View File

@@ -179,7 +179,7 @@ int WASAPI_ActivateDevice(SDL_AudioDevice *device)
}
SDL_assert(device->hidden->client != NULL);
if (WASAPI_PrepDevice(device) == -1) { // not async, fire it right away.
if (WASAPI_PrepDevice(device) < 0) { // not async, fire it right away.
return -1;
}

View File

@@ -468,7 +468,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
} else {
frame->pixels = pixels;
frame->pitch = (int) pitch;
if (SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer2, NULL) == -1) {
if (SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer2, NULL) < 0) {
retval = -1;
}
}
@@ -480,7 +480,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
} else {
frame->pixels = pixels;
frame->pitch = (int) pitch;
if (SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer, NULL) == -1) {
if (SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer, NULL) < 0) {
retval = -1;
}
}
@@ -497,7 +497,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
}
frame->pixels = pixels;
frame->pitch = (int) pitch;
if (SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMFMediaBuffer, NULL) == -1) {
if (SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMFMediaBuffer, NULL) < 0) {
retval = -1;
}
}

View File

@@ -411,7 +411,7 @@ int SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect)
if (haptic->effects[i].hweffect == NULL) {
/* Now let the backend create the real effect */
if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect) != 0) {
if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect) < 0) {
return -1; /* Backend failed to create effect */
}

View File

@@ -1303,7 +1303,7 @@ Uint32 SDL_hid_device_change_count(void)
Uint32 counter = 0;
#ifndef SDL_HIDAPI_DISABLED
if (SDL_hidapi_refcount == 0 && SDL_hid_init() != 0) {
if (SDL_hidapi_refcount == 0 && SDL_hid_init() < 0) {
return 0;
}
@@ -1414,7 +1414,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
struct hid_device_info *dev;
struct SDL_hid_device_info *devs = NULL, *last = NULL;
if (SDL_hidapi_refcount == 0 && SDL_hid_init() != 0) {
if (SDL_hidapi_refcount == 0 && SDL_hid_init() < 0) {
return NULL;
}
@@ -1504,7 +1504,7 @@ SDL_hid_device *SDL_hid_open(unsigned short vendor_id, unsigned short product_id
#if defined(HAVE_PLATFORM_BACKEND) || defined(HAVE_DRIVER_BACKEND) || defined(HAVE_LIBUSB)
void *pDevice = NULL;
if (SDL_hidapi_refcount == 0 && SDL_hid_init() != 0) {
if (SDL_hidapi_refcount == 0 && SDL_hid_init() < 0) {
return NULL;
}
@@ -1543,7 +1543,7 @@ SDL_hid_device *SDL_hid_open_path(const char *path)
#if defined(HAVE_PLATFORM_BACKEND) || defined(HAVE_DRIVER_BACKEND) || defined(HAVE_LIBUSB)
void *pDevice = NULL;
if (SDL_hidapi_refcount == 0 && SDL_hid_init() != 0) {
if (SDL_hidapi_refcount == 0 && SDL_hid_init() < 0) {
return NULL;
}

View File

@@ -1079,7 +1079,7 @@ static int HIDAPI_DriverPS5_InternalSendJoystickEffect(SDL_DriverPS5_Context *ct
SDL_memcpy(&data[report_size - sizeof(unCRC)], &unCRC, sizeof(unCRC));
}
if (SDL_HIDAPI_LockRumble() != 0) {
if (SDL_HIDAPI_LockRumble() < 0) {
return -1;
}

View File

@@ -256,7 +256,7 @@ int SDL_HIDAPI_SendRumble(SDL_HIDAPI_Device *device, const Uint8 *data, int size
return SDL_SetError("Tried to send rumble with invalid size");
}
if (SDL_HIDAPI_LockRumble() != 0) {
if (SDL_HIDAPI_LockRumble() < 0) {
return -1;
}

View File

@@ -145,7 +145,7 @@ static int HIDAPI_DriverShield_SendCommand(SDL_HIDAPI_Device *device, Uint8 cmd,
return SDL_SetError("Command data exceeds HID report size");
}
if (SDL_HIDAPI_LockRumble() != 0) {
if (SDL_HIDAPI_LockRumble() < 0) {
return -1;
}

View File

@@ -218,7 +218,7 @@ static SDL_bool WriteOutput(SDL_DriverWii_Context *ctx, const Uint8 *data, int s
return SDL_hid_write(ctx->device->dev, data, size) >= 0;
} else {
/* Use the rumble thread for general asynchronous writes */
if (SDL_HIDAPI_LockRumble() != 0) {
if (SDL_HIDAPI_LockRumble() < 0) {
return SDL_FALSE;
}
return SDL_HIDAPI_SendRumbleAndUnlock(ctx->device, data, size) >= 0;

View File

@@ -235,7 +235,7 @@ static SDL_bool SendProtocolPacket(SDL_DriverXboxOne_Context *ctx, const Uint8 *
ctx->send_time = SDL_GetTicks();
if (SDL_HIDAPI_LockRumble() != 0) {
if (SDL_HIDAPI_LockRumble() < 0) {
return SDL_FALSE;
}
if (SDL_HIDAPI_SendRumbleAndUnlock(ctx->device, data, size) != size) {
@@ -470,7 +470,7 @@ static int HIDAPI_DriverXboxOne_UpdateRumble(SDL_DriverXboxOne_Context *ctx)
/* We're no longer pending, even if we fail to send the rumble below */
ctx->rumble_pending = SDL_FALSE;
if (SDL_HIDAPI_LockRumble() != 0) {
if (SDL_HIDAPI_LockRumble() < 0) {
return -1;
}

View File

@@ -99,7 +99,7 @@ SDL_AppResult SDL_InitMainCallbacks(int argc, char* argv[], SDL_AppInit_func app
const SDL_AppResult rc = appinit(&SDL_main_appstate, argc, argv);
if (SDL_AtomicCompareAndSwap(&apprc, SDL_APP_CONTINUE, rc) && (rc == SDL_APP_CONTINUE)) { // bounce if SDL_AppInit already said abort, otherwise...
// make sure we definitely have events initialized, even if the app didn't do it.
if (SDL_InitSubSystem(SDL_INIT_EVENTS) == -1) {
if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
SDL_AtomicSet(&apprc, SDL_APP_FAILURE);
return -1;
}

View File

@@ -351,7 +351,7 @@ static int FlushRenderCommandsIfTextureNeeded(SDL_Texture *texture)
int SDL_FlushRenderer(SDL_Renderer *renderer)
{
if (FlushRenderCommands(renderer) == -1) {
if (FlushRenderCommands(renderer) < 0) {
return -1;
}
renderer->InvalidateCachedState(renderer);
@@ -1001,7 +1001,7 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props)
#else
const int rc = SDL_SetError("SDL not built with software renderer");
#endif
if (rc == -1) {
if (rc < 0) {
goto error;
}
} else {
@@ -1034,7 +1034,7 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props)
}
}
if (rc == -1) {
if (rc < 0) {
if (!name || !attempted) {
SDL_SetError("Couldn't find matching render driver");
}

View File

@@ -1228,7 +1228,7 @@ EGLSurface SDL_EGL_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, Nat
EGLSurface surface;
if (SDL_EGL_ChooseConfig(_this) != 0) {
if (SDL_EGL_ChooseConfig(_this) < 0) {
return EGL_NO_SURFACE;
}
@@ -1319,7 +1319,7 @@ SDL_EGL_CreateOffscreenSurface(SDL_VideoDevice *_this, int width, int height)
attributes[1] = width;
attributes[3] = height;
if (SDL_EGL_ChooseConfig(_this) != 0) {
if (SDL_EGL_ChooseConfig(_this) < 0) {
return EGL_NO_SURFACE;
}

View File

@@ -1174,7 +1174,7 @@ int SDL_ConvertPixels_RGB_to_YUV(int width, int height,
/* convert src/src_format to tmp/XBGR2101010 */
ret = SDL_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_XBGR2101010, dst_colorspace, dst_properties, tmp, tmp_pitch);
if (ret == -1) {
if (ret < 0) {
SDL_free(tmp);
return ret;
}
@@ -1198,7 +1198,7 @@ int SDL_ConvertPixels_RGB_to_YUV(int width, int height,
/* convert src/src_format to tmp/ARGB8888 */
ret = SDL_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, dst_colorspace, dst_properties, tmp, tmp_pitch);
if (ret == -1) {
if (ret < 0) {
SDL_free(tmp);
return ret;
}