From 447b508a77b8601d23ca48cf189fe4436ab33572 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 30 Nov 2023 00:14:27 -0500 Subject: [PATCH] error: SDL's allocators now call SDL_OutOfMemory on error. This means the allocator's caller doesn't need to use SDL_OutOfMemory directly if the allocation fails. This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc (all of these regardless of if the app supplied a custom allocator or we're using system malloc() or an internal copy of dlmalloc under the hood), SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup... probably others. If it returns something you can pass to SDL_free, it should work. The caller might still need to use SDL_OutOfMemory if something that wasn't SDL allocated the memory: operator new in C++ code, Objective-C's alloc message, win32 GlobalAlloc, etc. Fixes #8642. --- src/SDL_hashtable.c | 3 -- src/SDL_hints.c | 6 +-- src/SDL_list.c | 2 +- src/SDL_properties.c | 18 +++----- src/audio/SDL_audio.c | 16 +++---- src/audio/SDL_audiocvt.c | 8 +--- src/audio/SDL_audioqueue.c | 8 ++-- src/audio/SDL_wave.c | 30 ++++++------- src/audio/aaudio/SDL_aaudio.c | 4 +- src/audio/alsa/SDL_alsa_audio.c | 4 +- src/audio/android/SDL_androidaudio.c | 2 +- src/audio/coreaudio/SDL_coreaudio.m | 4 +- src/audio/directsound/SDL_directsound.c | 2 +- src/audio/disk/SDL_diskaudio.c | 4 +- src/audio/dsp/SDL_dspaudio.c | 4 +- src/audio/dummy/SDL_dummyaudio.c | 4 +- src/audio/emscripten/SDL_emscriptenaudio.c | 4 +- src/audio/jack/SDL_jackaudio.c | 6 +-- src/audio/n3ds/SDL_n3dsaudio.c | 4 +- src/audio/netbsd/SDL_netbsdaudio.c | 4 +- src/audio/openslES/SDL_openslES.c | 2 +- src/audio/pipewire/SDL_pipewire.c | 3 +- src/audio/ps2/SDL_ps2audio.c | 2 +- src/audio/psp/SDL_pspaudio.c | 2 +- src/audio/pulseaudio/SDL_pulseaudio.c | 4 +- src/audio/qnx/SDL_qsa_audio.c | 4 +- src/audio/sndio/SDL_sndioaudio.c | 6 +-- src/audio/vita/SDL_vitaaudio.c | 5 +-- src/audio/wasapi/SDL_wasapi.c | 4 +- src/core/linux/SDL_evdev.c | 12 +++--- src/core/linux/SDL_udev.c | 4 +- src/core/windows/SDL_immdevice.c | 2 - src/events/SDL_events.c | 3 -- src/events/SDL_mouse.c | 5 +-- src/events/SDL_touch.c | 12 +++--- src/file/SDL_rwops.c | 9 +--- src/file/n3ds/SDL_rwopsromfs.c | 1 - src/filesystem/android/SDL_sysfilesystem.c | 1 - src/filesystem/cocoa/SDL_sysfilesystem.m | 17 ++------ src/filesystem/emscripten/SDL_sysfilesystem.c | 10 +---- src/filesystem/gdk/SDL_sysfilesystem.cpp | 1 - src/filesystem/haiku/SDL_sysfilesystem.cc | 21 +++------ src/filesystem/n3ds/SDL_sysfilesystem.c | 1 - src/filesystem/riscos/SDL_sysfilesystem.c | 3 -- src/filesystem/unix/SDL_sysfilesystem.c | 15 +------ src/filesystem/vita/SDL_sysfilesystem.c | 1 - src/filesystem/windows/SDL_sysfilesystem.c | 3 -- src/filesystem/winrt/SDL_sysfilesystem.cpp | 3 -- src/haptic/SDL_haptic.c | 2 - src/haptic/android/SDL_syshaptic.c | 1 - src/haptic/darwin/SDL_syshaptic.c | 43 +++++++------------ src/haptic/linux/SDL_syshaptic.c | 9 ++-- src/haptic/windows/SDL_dinputhaptic.c | 42 ++++++++---------- src/haptic/windows/SDL_windowshaptic.c | 5 +-- src/haptic/windows/SDL_xinputhaptic.c | 13 +++--- src/joystick/SDL_gamepad.c | 27 ++---------- src/joystick/SDL_joystick.c | 5 --- src/joystick/apple/SDL_mfijoystick.m | 2 - src/joystick/bsd/SDL_bsdjoystick.c | 3 +- src/joystick/darwin/SDL_iokitjoystick.c | 3 +- src/joystick/haiku/SDL_haikujoystick.cc | 14 +++--- src/joystick/hidapi/SDL_hidapi_gamecube.c | 1 - src/joystick/hidapi/SDL_hidapi_luna.c | 1 - src/joystick/hidapi/SDL_hidapi_ps3.c | 2 - src/joystick/hidapi/SDL_hidapi_ps4.c | 1 - src/joystick/hidapi/SDL_hidapi_ps5.c | 1 - src/joystick/hidapi/SDL_hidapi_rumble.c | 2 +- src/joystick/hidapi/SDL_hidapi_shield.c | 1 - src/joystick/hidapi/SDL_hidapi_stadia.c | 1 - src/joystick/hidapi/SDL_hidapi_steam.c | 1 - src/joystick/hidapi/SDL_hidapi_switch.c | 1 - src/joystick/hidapi/SDL_hidapi_wii.c | 1 - src/joystick/hidapi/SDL_hidapi_xbox360.c | 1 - src/joystick/hidapi/SDL_hidapi_xbox360w.c | 1 - src/joystick/hidapi/SDL_hidapi_xboxone.c | 1 - src/joystick/hidapi/SDL_hidapijoystick.c | 2 +- src/joystick/linux/SDL_sysjoystick.c | 6 +-- src/joystick/virtual/SDL_virtualjoystick.c | 8 ++-- src/joystick/windows/SDL_dinputjoystick.c | 2 +- src/joystick/windows/SDL_rawinputjoystick.c | 14 +++--- .../windows/SDL_windows_gaming_input.c | 3 +- src/joystick/windows/SDL_windowsjoystick.c | 6 +-- src/locale/SDL_locale.c | 1 - src/locale/unix/SDL_syslocale.c | 2 +- src/locale/windows/SDL_syslocale.c | 2 +- src/misc/windows/SDL_sysurl.c | 2 +- src/misc/winrt/SDL_sysurl.cpp | 2 +- src/render/SDL_render.c | 19 ++++---- src/render/SDL_yuv_sw.c | 3 -- src/render/direct3d/SDL_render_d3d.c | 6 +-- src/render/direct3d11/SDL_render_d3d11.c | 6 +-- src/render/direct3d12/SDL_render_d3d12.c | 6 +-- src/render/metal/SDL_render_metal.m | 5 +-- src/render/opengl/SDL_render_gl.c | 8 ++-- src/render/opengles2/SDL_render_gles2.c | 11 ++--- src/render/ps2/SDL_render_ps2.c | 6 +-- src/render/psp/SDL_render_psp.c | 12 +++--- src/render/software/SDL_render_sw.c | 2 - src/render/vitagxm/SDL_render_vita_gxm.c | 6 +-- src/sensor/SDL_sensor.c | 3 -- src/sensor/android/SDL_androidsensor.c | 2 +- src/sensor/coremotion/SDL_coremotionsensor.m | 4 +- src/sensor/vita/SDL_vitasensor.c | 4 +- src/sensor/windows/SDL_windowssensor.c | 4 +- src/stdlib/SDL_malloc.c | 9 ++++ src/test/SDL_test_common.c | 1 - src/thread/SDL_thread.c | 9 +--- src/thread/generic/SDL_syscond.c | 2 - src/thread/generic/SDL_sysmutex.c | 2 - src/thread/generic/SDL_sysrwlock.c | 1 - src/thread/generic/SDL_syssem.c | 1 - src/thread/n3ds/SDL_syscond.c | 2 - src/thread/n3ds/SDL_sysmutex.c | 2 - src/thread/n3ds/SDL_syssem.c | 1 - src/thread/ps2/SDL_syssem.c | 2 - src/thread/psp/SDL_syscond.c | 2 - src/thread/psp/SDL_sysmutex.c | 2 - src/thread/psp/SDL_syssem.c | 2 - src/thread/pthread/SDL_sysmutex.c | 2 - src/thread/pthread/SDL_sysrwlock.c | 2 - src/thread/pthread/SDL_syssem.c | 2 - src/thread/vita/SDL_syscond.c | 2 - src/thread/vita/SDL_sysmutex.c | 2 - src/thread/vita/SDL_syssem.c | 2 - src/thread/windows/SDL_syscond_cv.c | 15 ++----- src/thread/windows/SDL_sysmutex.c | 13 ++---- src/thread/windows/SDL_sysrwlock_srw.c | 5 +-- src/thread/windows/SDL_syssem.c | 9 +--- src/timer/SDL_timer.c | 3 -- src/video/SDL_RLEaccel.c | 4 +- src/video/SDL_clipboard.c | 4 +- src/video/SDL_egl.c | 2 +- src/video/SDL_pixels.c | 6 --- src/video/SDL_surface.c | 4 -- src/video/SDL_video.c | 11 +---- src/video/SDL_vulkan_utils.c | 6 --- src/video/SDL_yuv.c | 14 +++--- src/video/android/SDL_androidmouse.c | 3 -- src/video/android/SDL_androidvideo.c | 2 - src/video/android/SDL_androidwindow.c | 2 +- src/video/cocoa/SDL_cocoaclipboard.m | 2 - src/video/cocoa/SDL_cocoamouse.m | 2 +- src/video/cocoa/SDL_cocoavideo.m | 1 - src/video/cocoa/SDL_cocoawindow.m | 1 - src/video/dummy/SDL_nullvideo.c | 1 - src/video/emscripten/SDL_emscriptenmouse.c | 7 +-- src/video/emscripten/SDL_emscriptenvideo.c | 3 +- src/video/gdk/SDL_gdktextinput.cpp | 10 +---- src/video/haiku/SDL_bvideo.cc | 2 - src/video/kmsdrm/SDL_kmsdrmmouse.c | 5 +-- src/video/kmsdrm/SDL_kmsdrmvideo.c | 11 ++--- src/video/n3ds/SDL_n3dsframebuffer.c | 2 +- src/video/n3ds/SDL_n3dsvideo.c | 5 +-- src/video/ngage/SDL_ngagevideo.cpp | 2 - src/video/ngage/SDL_ngagewindow.cpp | 2 +- src/video/offscreen/SDL_offscreenvideo.c | 1 - src/video/offscreen/SDL_offscreenwindow.c | 2 +- src/video/ps2/SDL_ps2video.c | 1 - src/video/psp/SDL_pspvideo.c | 5 +-- src/video/raspberry/SDL_rpimouse.c | 2 - src/video/raspberry/SDL_rpivideo.c | 4 +- src/video/riscos/SDL_riscosframebuffer.c | 2 +- src/video/riscos/SDL_riscosmodes.c | 6 +-- src/video/riscos/SDL_riscosmouse.c | 6 +-- src/video/riscos/SDL_riscosvideo.c | 2 - src/video/riscos/SDL_riscoswindow.c | 2 +- src/video/uikit/SDL_uikitvideo.m | 12 +++--- src/video/vita/SDL_vitavideo.c | 5 +-- src/video/vivante/SDL_vivantevideo.c | 6 +-- src/video/wayland/SDL_waylanddatamanager.c | 12 +++--- src/video/wayland/SDL_waylandevents.c | 18 ++------ src/video/wayland/SDL_waylandmessagebox.c | 2 +- src/video/wayland/SDL_waylandmouse.c | 15 +------ src/video/wayland/SDL_waylandvideo.c | 2 - src/video/wayland/SDL_waylandwindow.c | 2 +- src/video/windows/SDL_windowsclipboard.c | 2 - src/video/windows/SDL_windowsframebuffer.c | 2 +- src/video/windows/SDL_windowsmessagebox.c | 1 - src/video/windows/SDL_windowsmouse.c | 10 +---- src/video/windows/SDL_windowsopengl.c | 2 +- src/video/windows/SDL_windowsvideo.c | 1 - src/video/windows/SDL_windowswindow.c | 4 +- src/video/winrt/SDL_winrtmouse.cpp | 2 - src/video/winrt/SDL_winrtvideo.cpp | 3 -- src/video/x11/SDL_x11clipboard.c | 4 +- src/video/x11/SDL_x11framebuffer.c | 2 +- src/video/x11/SDL_x11messagebox.c | 4 +- src/video/x11/SDL_x11modes.c | 8 ++-- src/video/x11/SDL_x11mouse.c | 16 +------ src/video/x11/SDL_x11opengl.c | 2 +- src/video/x11/SDL_x11video.c | 2 - src/video/x11/SDL_x11window.c | 9 ++-- src/video/x11/SDL_x11xinput2.c | 1 - test/testffmpeg.c | 3 -- test/testshape.c | 2 +- test/testutils.c | 18 ++------ test/testvulkan.c | 6 --- 197 files changed, 313 insertions(+), 742 deletions(-) diff --git a/src/SDL_hashtable.c b/src/SDL_hashtable.c index 0b8980598..b6a8b0d49 100644 --- a/src/SDL_hashtable.c +++ b/src/SDL_hashtable.c @@ -54,14 +54,12 @@ SDL_HashTable *SDL_CreateHashTable(void *data, const Uint32 num_buckets, const S table = (SDL_HashTable *) SDL_calloc(1, sizeof (SDL_HashTable)); if (!table) { - SDL_OutOfMemory(); return NULL; } table->table = (SDL_HashItem **) SDL_calloc(num_buckets, sizeof (SDL_HashItem *)); if (!table->table) { SDL_free(table); - SDL_OutOfMemory(); return NULL; } @@ -92,7 +90,6 @@ SDL_bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const vo // !!! FIXME: grow and rehash table if it gets too saturated. item = (SDL_HashItem *) SDL_malloc(sizeof (SDL_HashItem)); if (!item) { - SDL_OutOfMemory(); return SDL_FALSE; } diff --git a/src/SDL_hints.c b/src/SDL_hints.c index 3e792c6d5..e45823a4e 100644 --- a/src/SDL_hints.c +++ b/src/SDL_hints.c @@ -226,7 +226,7 @@ int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userd entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry)); if (!entry) { - return SDL_OutOfMemory(); + return -1; } entry->callback = callback; entry->userdata = userdata; @@ -241,13 +241,13 @@ int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userd hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); if (!hint) { SDL_free(entry); - return SDL_OutOfMemory(); + return -1; } hint->name = SDL_strdup(name); if (!hint->name) { SDL_free(entry); SDL_free(hint); - return SDL_OutOfMemory(); + return -1; } hint->value = NULL; hint->priority = SDL_HINT_DEFAULT; diff --git a/src/SDL_list.c b/src/SDL_list.c index 64c39245e..b6ea10d10 100644 --- a/src/SDL_list.c +++ b/src/SDL_list.c @@ -28,7 +28,7 @@ int SDL_ListAdd(SDL_ListNode **head, void *ent) SDL_ListNode *node = SDL_malloc(sizeof(*node)); if (!node) { - return SDL_OutOfMemory(); + return -1; } node->entry = ent; diff --git a/src/SDL_properties.c b/src/SDL_properties.c index 92c260fc1..b883a4d37 100644 --- a/src/SDL_properties.c +++ b/src/SDL_properties.c @@ -271,7 +271,7 @@ int SDL_SetPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *v property = (SDL_Property *)SDL_calloc(1, sizeof(*property)); if (!property) { - return SDL_OutOfMemory(); + return -1; } property->type = SDL_PROPERTY_TYPE_POINTER; property->value.pointer_value = value; @@ -290,7 +290,7 @@ int SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value) property = (SDL_Property *)SDL_calloc(1, sizeof(*property)); if (!property) { - return SDL_OutOfMemory(); + return -1; } property->type = SDL_PROPERTY_TYPE_POINTER; property->value.pointer_value = value; @@ -308,13 +308,13 @@ int SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char * property = (SDL_Property *)SDL_calloc(1, sizeof(*property)); if (!property) { - return SDL_OutOfMemory(); + return -1; } property->type = SDL_PROPERTY_TYPE_STRING; property->value.string_value = SDL_strdup(value); if (!property->value.string_value) { SDL_free(property); - return SDL_OutOfMemory(); + return -1; } return SDL_PrivateSetProperty(props, name, property); } @@ -323,7 +323,7 @@ int SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value { SDL_Property *property = (SDL_Property *)SDL_calloc(1, sizeof(*property)); if (!property) { - return SDL_OutOfMemory(); + return -1; } property->type = SDL_PROPERTY_TYPE_NUMBER; property->value.number_value = value; @@ -334,7 +334,7 @@ int SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value) { SDL_Property *property = (SDL_Property *)SDL_calloc(1, sizeof(*property)); if (!property) { - return SDL_OutOfMemory(); + return -1; } property->type = SDL_PROPERTY_TYPE_FLOAT; property->value.float_value = value; @@ -345,7 +345,7 @@ int SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool va { SDL_Property *property = (SDL_Property *)SDL_calloc(1, sizeof(*property)); if (!property) { - return SDL_OutOfMemory(); + return -1; } property->type = SDL_PROPERTY_TYPE_BOOLEAN; property->value.boolean_value = value ? SDL_TRUE : SDL_FALSE; @@ -478,8 +478,6 @@ const char *SDL_GetStringProperty(SDL_PropertiesID props, const char *name, cons SDL_asprintf(&property->string_storage, "%" SDL_PRIs64 "", property->value.number_value); if (property->string_storage) { value = property->string_storage; - } else { - SDL_OutOfMemory(); } } break; @@ -490,8 +488,6 @@ const char *SDL_GetStringProperty(SDL_PropertiesID props, const char *name, cons SDL_asprintf(&property->string_storage, "%f", property->value.float_value); if (property->string_storage) { value = property->string_storage; - } else { - SDL_OutOfMemory(); } } break; diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 168a909fa..b47c840b6 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -512,14 +512,12 @@ static SDL_AudioDevice *CreatePhysicalAudioDevice(const char *name, SDL_bool isc SDL_AudioDevice *device = (SDL_AudioDevice *)SDL_calloc(1, sizeof(SDL_AudioDevice)); if (!device) { - SDL_OutOfMemory(); return NULL; } device->name = SDL_strdup(name); if (!device->name) { SDL_free(device); - SDL_OutOfMemory(); return NULL; } @@ -840,7 +838,7 @@ int SDL_InitAudio(const char *driver_name) if (!driver_name_copy) { SDL_DestroyRWLock(device_hash_lock); SDL_DestroyHashTable(device_hash); - return SDL_OutOfMemory(); + return -1; } while (driver_attempt && *driver_attempt != 0 && !initialized) { @@ -1272,7 +1270,6 @@ static SDL_AudioDeviceID *GetAudioDevices(int *reqcount, SDL_bool iscapture) retval = (SDL_AudioDeviceID *) SDL_malloc((num_devices + 1) * sizeof (SDL_AudioDeviceID)); if (!retval) { num_devices = 0; - SDL_OutOfMemory(); } else { int devs_seen = 0; const void *key; @@ -1360,9 +1357,6 @@ char *SDL_GetAudioDeviceName(SDL_AudioDeviceID devid) SDL_AudioDevice *device = ObtainPhysicalAudioDevice(devid); if (device) { retval = SDL_strdup(device->name); - if (!retval) { - SDL_OutOfMemory(); - } } ReleaseAudioDevice(device); @@ -1574,14 +1568,14 @@ static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec device->work_buffer = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), device->work_buffer_size); if (!device->work_buffer) { ClosePhysicalAudioDevice(device); - return SDL_OutOfMemory(); + return -1; } if (device->spec.format != SDL_AUDIO_F32) { device->mix_buffer = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), device->work_buffer_size); if (!device->mix_buffer) { ClosePhysicalAudioDevice(device); - return SDL_OutOfMemory(); + return -1; } } @@ -1630,7 +1624,7 @@ SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSp // uhoh, this device is undead, and just waiting to be cleaned up. Refuse explicit opens. 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_OutOfMemory(); + /* 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... SDL_free(logdev); } else { @@ -1704,7 +1698,7 @@ int SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallbac if (callback && !device->postmix_buffer) { device->postmix_buffer = (float *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), device->work_buffer_size); if (!device->postmix_buffer) { - retval = SDL_OutOfMemory(); + retval = -1; } } diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c index a10141009..27f69f702 100644 --- a/src/audio/SDL_audiocvt.c +++ b/src/audio/SDL_audiocvt.c @@ -389,7 +389,7 @@ static int UpdateAudioStreamInputSpec(SDL_AudioStream *stream, const SDL_AudioSp if (stream->history_buffer_allocation < history_buffer_allocation) { history_buffer = (Uint8 *) SDL_aligned_alloc(SDL_SIMDGetAlignment(), history_buffer_allocation); if (!history_buffer) { - return SDL_OutOfMemory(); + return -1; } SDL_aligned_free(stream->history_buffer); stream->history_buffer = history_buffer; @@ -409,7 +409,6 @@ SDL_AudioStream *SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_ SDL_AudioStream *retval = (SDL_AudioStream *)SDL_calloc(1, sizeof(SDL_AudioStream)); if (!retval) { - SDL_OutOfMemory(); return NULL; } @@ -722,7 +721,6 @@ static Uint8 *EnsureAudioStreamWorkBufferSize(SDL_AudioStream *stream, size_t ne Uint8 *ptr = (Uint8 *) SDL_aligned_alloc(SDL_SIMDGetAlignment(), newlen); if (!ptr) { - SDL_OutOfMemory(); return NULL; // previous work buffer is still valid! } @@ -1234,9 +1232,7 @@ int SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data dstlen = SDL_GetAudioStreamAvailable(stream); if (dstlen >= 0) { dst = (Uint8 *)SDL_malloc(dstlen); - if (!dst) { - SDL_OutOfMemory(); - } else { + if (dst) { retval = (SDL_GetAudioStreamData(stream, dst, dstlen) >= 0) ? 0 : -1; } } diff --git a/src/audio/SDL_audioqueue.c b/src/audio/SDL_audioqueue.c index 763809fdc..085e8aaee 100644 --- a/src/audio/SDL_audioqueue.c +++ b/src/audio/SDL_audioqueue.c @@ -150,7 +150,7 @@ static int WriteToChunkedAudioTrack(void *ctx, const Uint8 *data, size_t len) chunk = CreateAudioTrackChunk(track); if (!chunk) { - return SDL_OutOfMemory(); + return -1; } SDL_assert((track->head == NULL) && (track->tail == NULL) && (track->queued_bytes == 0)); @@ -189,7 +189,7 @@ static int WriteToChunkedAudioTrack(void *ctx, const Uint8 *data, size_t len) DestroyAudioChunks(next); - return SDL_OutOfMemory(); + return -1; } track->tail = chunk; @@ -256,7 +256,6 @@ static SDL_AudioTrack *CreateChunkedAudioTrack(const SDL_AudioSpec *spec, size_t SDL_ChunkedAudioTrack *track = (SDL_ChunkedAudioTrack *)SDL_calloc(1, sizeof(*track)); if (!track) { - SDL_OutOfMemory(); return NULL; } @@ -276,7 +275,6 @@ SDL_AudioQueue *SDL_CreateAudioQueue(size_t chunk_size) SDL_AudioQueue *queue = (SDL_AudioQueue *)SDL_calloc(1, sizeof(*queue)); if (!queue) { - SDL_OutOfMemory(); return NULL; } @@ -398,7 +396,7 @@ int SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, cons SDL_AudioTrack *new_track = CreateChunkedAudioTrack(spec, queue->chunk_size); if (!new_track) { - return SDL_OutOfMemory(); + return -1; } if (track) { diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c index 76785cf91..cb3732305 100644 --- a/src/audio/SDL_wave.c +++ b/src/audio/SDL_wave.c @@ -440,7 +440,7 @@ static int MS_ADPCM_Init(WaveFile *file, size_t datalength) coeffdata = (MS_ADPCM_CoeffData *)SDL_malloc(sizeof(MS_ADPCM_CoeffData) + coeffcount * 4); file->decoderdata = coeffdata; /* Freed in cleanup. */ if (!coeffdata) { - return SDL_OutOfMemory(); + return -1; } coeffdata->coeff = &coeffdata->aligndummy; coeffdata->coeffcount = (Uint16)coeffcount; @@ -674,7 +674,7 @@ static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) /* The output size in bytes. May get modified if data is truncated. */ outputsize = (size_t)state.framestotal; if (SafeMult(&outputsize, state.framesize)) { - return SDL_OutOfMemory(); + return SDL_SetError("WAVE file too big"); } else if (outputsize > SDL_MAX_UINT32 || state.framestotal > SIZE_MAX) { return SDL_SetError("WAVE file too big"); } @@ -683,7 +683,7 @@ static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) state.output.size = outputsize / sizeof(Sint16); state.output.data = (Sint16 *)SDL_calloc(1, outputsize); if (!state.output.data) { - return SDL_OutOfMemory(); + return -1; } state.cstate = cstate; @@ -1065,7 +1065,7 @@ static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len /* The output size in bytes. May get modified if data is truncated. */ outputsize = (size_t)state.framestotal; if (SafeMult(&outputsize, state.framesize)) { - return SDL_OutOfMemory(); + return SDL_SetError("WAVE file too big"); } else if (outputsize > SDL_MAX_UINT32 || state.framestotal > SIZE_MAX) { return SDL_SetError("WAVE file too big"); } @@ -1074,13 +1074,13 @@ static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len state.output.size = outputsize / sizeof(Sint16); state.output.data = (Sint16 *)SDL_malloc(outputsize); if (!state.output.data) { - return SDL_OutOfMemory(); + return -1; } cstate = (Sint8 *)SDL_calloc(state.channels, sizeof(Sint8)); if (!cstate) { SDL_free(state.output.data); - return SDL_OutOfMemory(); + return -1; } state.cstate = cstate; @@ -1221,12 +1221,12 @@ static int LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) sample_count = (size_t)file->sampleframes; if (SafeMult(&sample_count, format->channels)) { - return SDL_OutOfMemory(); + return SDL_SetError("WAVE file too big"); } expanded_len = sample_count; if (SafeMult(&expanded_len, sizeof(Sint16))) { - return SDL_OutOfMemory(); + return SDL_SetError("WAVE file too big"); } else if (expanded_len > SDL_MAX_UINT32 || file->sampleframes > SIZE_MAX) { return SDL_SetError("WAVE file too big"); } @@ -1234,7 +1234,7 @@ static int LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) /* 1 to avoid allocating zero bytes, to keep static analysis happy. */ src = (Uint8 *)SDL_realloc(chunk->data, expanded_len ? expanded_len : 1); if (!src) { - return SDL_OutOfMemory(); + return -1; } chunk->data = NULL; chunk->size = 0; @@ -1352,12 +1352,12 @@ static int PCM_ConvertSint24ToSint32(WaveFile *file, Uint8 **audio_buf, Uint32 * sample_count = (size_t)file->sampleframes; if (SafeMult(&sample_count, format->channels)) { - return SDL_OutOfMemory(); + return SDL_SetError("WAVE file too big"); } expanded_len = sample_count; if (SafeMult(&expanded_len, sizeof(Sint32))) { - return SDL_OutOfMemory(); + return SDL_SetError("WAVE file too big"); } else if (expanded_len > SDL_MAX_UINT32 || file->sampleframes > SIZE_MAX) { return SDL_SetError("WAVE file too big"); } @@ -1365,7 +1365,7 @@ static int PCM_ConvertSint24ToSint32(WaveFile *file, Uint8 **audio_buf, Uint32 * /* 1 to avoid allocating zero bytes, to keep static analysis happy. */ ptr = (Uint8 *)SDL_realloc(chunk->data, expanded_len ? expanded_len : 1); if (!ptr) { - return SDL_OutOfMemory(); + return -1; } /* This pointer is now invalid. */ @@ -1421,7 +1421,7 @@ static int PCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) outputsize = (size_t)file->sampleframes; if (SafeMult(&outputsize, format->blockalign)) { - return SDL_OutOfMemory(); + return SDL_SetError("WAVE file too big"); } else if (outputsize > SDL_MAX_UINT32 || file->sampleframes > SIZE_MAX) { return SDL_SetError("WAVE file too big"); } @@ -1545,7 +1545,7 @@ static int WaveReadPartialChunkData(SDL_RWops *src, WaveChunk *chunk, size_t len if (length > 0) { chunk->data = (Uint8 *)SDL_malloc(length); if (!chunk->data) { - return SDL_OutOfMemory(); + return -1; } if (SDL_RWseek(src, chunk->position, SDL_RW_SEEK_SET) != chunk->position) { @@ -1611,7 +1611,7 @@ static int WaveReadFormat(WaveFile *file) } fmtsrc = SDL_RWFromConstMem(chunk->data, (int)chunk->size); if (!fmtsrc) { - return SDL_OutOfMemory(); + return -1; } if (!SDL_ReadU16LE(fmtsrc, &format->formattag) || diff --git a/src/audio/aaudio/SDL_aaudio.c b/src/audio/aaudio/SDL_aaudio.c index 668ffac05..d46f671b6 100644 --- a/src/audio/aaudio/SDL_aaudio.c +++ b/src/audio/aaudio/SDL_aaudio.c @@ -355,7 +355,7 @@ static int BuildAAudioStream(SDL_AudioDevice *device) hidden->mixbuf_bytes = (hidden->num_buffers * device->buffer_size); hidden->mixbuf = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), hidden->mixbuf_bytes); if (!hidden->mixbuf) { - return SDL_OutOfMemory(); + return -1; } hidden->processed_bytes = 0; hidden->callback_bytes = 0; @@ -398,7 +398,7 @@ static int AAUDIO_OpenDevice(SDL_AudioDevice *device) device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } return BuildAAudioStream(device); diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index e7505b88d..98953a96a 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -537,7 +537,7 @@ static int ALSA_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } // Open the audio device @@ -683,7 +683,7 @@ static int ALSA_OpenDevice(SDL_AudioDevice *device) if (!iscapture) { device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return SDL_OutOfMemory(); + return -1; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); } diff --git a/src/audio/android/SDL_androidaudio.c b/src/audio/android/SDL_androidaudio.c index b2147f336..55be7dddd 100644 --- a/src/audio/android/SDL_androidaudio.c +++ b/src/audio/android/SDL_androidaudio.c @@ -43,7 +43,7 @@ static int ANDROIDAUDIO_OpenDevice(SDL_AudioDevice *device) { device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } const SDL_bool iscapture = device->iscapture; diff --git a/src/audio/coreaudio/SDL_coreaudio.m b/src/audio/coreaudio/SDL_coreaudio.m index 0690de3e2..2133b992c 100644 --- a/src/audio/coreaudio/SDL_coreaudio.m +++ b/src/audio/coreaudio/SDL_coreaudio.m @@ -769,7 +769,7 @@ static int PrepareAudioQueue(SDL_AudioDevice *device) device->hidden->numAudioBuffers = numAudioBuffers; device->hidden->audioBuffer = SDL_calloc(numAudioBuffers, sizeof(AudioQueueBufferRef)); if (device->hidden->audioBuffer == NULL) { - return SDL_OutOfMemory(); + return -1; } #if DEBUG_COREAUDIO @@ -833,7 +833,7 @@ static int COREAUDIO_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (device->hidden == NULL) { - return SDL_OutOfMemory(); + return -1; } #ifndef MACOSX_COREAUDIO diff --git a/src/audio/directsound/SDL_directsound.c b/src/audio/directsound/SDL_directsound.c index f9ae97871..305f3d461 100644 --- a/src/audio/directsound/SDL_directsound.c +++ b/src/audio/directsound/SDL_directsound.c @@ -492,7 +492,7 @@ static int DSOUND_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } // Open the audio device diff --git a/src/audio/disk/SDL_diskaudio.c b/src/audio/disk/SDL_diskaudio.c index bdcb8b3be..8a5233187 100644 --- a/src/audio/disk/SDL_diskaudio.c +++ b/src/audio/disk/SDL_diskaudio.c @@ -113,7 +113,7 @@ static int DISKAUDIO_OpenDevice(SDL_AudioDevice *device) device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } if (envr) { @@ -132,7 +132,7 @@ static int DISKAUDIO_OpenDevice(SDL_AudioDevice *device) if (!iscapture) { device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return SDL_OutOfMemory(); + return -1; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); } diff --git a/src/audio/dsp/SDL_dspaudio.c b/src/audio/dsp/SDL_dspaudio.c index 9a2c918be..a9c3c22d2 100644 --- a/src/audio/dsp/SDL_dspaudio.c +++ b/src/audio/dsp/SDL_dspaudio.c @@ -71,7 +71,7 @@ static int DSP_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } // Open the audio device; we hardcode the device path in `device->name` for lack of better info, so use that. @@ -192,7 +192,7 @@ static int DSP_OpenDevice(SDL_AudioDevice *device) if (!device->iscapture) { device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return SDL_OutOfMemory(); + return -1; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); } diff --git a/src/audio/dummy/SDL_dummyaudio.c b/src/audio/dummy/SDL_dummyaudio.c index 9b2068a48..91775d372 100644 --- a/src/audio/dummy/SDL_dummyaudio.c +++ b/src/audio/dummy/SDL_dummyaudio.c @@ -40,13 +40,13 @@ static int DUMMYAUDIO_OpenDevice(SDL_AudioDevice *device) device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } if (!device->iscapture) { device->hidden->mixbuf = (Uint8 *) SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return SDL_OutOfMemory(); + return -1; } } diff --git a/src/audio/emscripten/SDL_emscriptenaudio.c b/src/audio/emscripten/SDL_emscriptenaudio.c index 64b195221..6c8fc60a4 100644 --- a/src/audio/emscripten/SDL_emscriptenaudio.c +++ b/src/audio/emscripten/SDL_emscriptenaudio.c @@ -178,7 +178,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } // limit to native freq @@ -189,7 +189,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device) if (!device->iscapture) { device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return SDL_OutOfMemory(); + return -1; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); } diff --git a/src/audio/jack/SDL_jackaudio.c b/src/audio/jack/SDL_jackaudio.c index 78a3dac30..8c79a7eee 100644 --- a/src/audio/jack/SDL_jackaudio.c +++ b/src/audio/jack/SDL_jackaudio.c @@ -297,7 +297,7 @@ static int JACK_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } client = JACK_jack_client_open(GetJackAppName(), JackNoStartServer, &status, NULL); @@ -343,7 +343,7 @@ static int JACK_OpenDevice(SDL_AudioDevice *device) device->hidden->iobuffer = (float *)SDL_calloc(1, device->buffer_size); if (!device->hidden->iobuffer) { SDL_free(audio_ports); - return SDL_OutOfMemory(); + return -1; } } @@ -351,7 +351,7 @@ static int JACK_OpenDevice(SDL_AudioDevice *device) device->hidden->sdlports = (jack_port_t **)SDL_calloc(channels, sizeof(jack_port_t *)); if (!device->hidden->sdlports) { SDL_free(audio_ports); - return SDL_OutOfMemory(); + return -1; } for (i = 0; i < channels; i++) { diff --git a/src/audio/n3ds/SDL_n3dsaudio.c b/src/audio/n3ds/SDL_n3dsaudio.c index a515d07d0..7692d7853 100644 --- a/src/audio/n3ds/SDL_n3dsaudio.c +++ b/src/audio/n3ds/SDL_n3dsaudio.c @@ -84,7 +84,7 @@ static int N3DSAUDIO_OpenDevice(SDL_AudioDevice *device) device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } // Initialise the DSP service @@ -135,7 +135,7 @@ static int N3DSAUDIO_OpenDevice(SDL_AudioDevice *device) device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return SDL_OutOfMemory(); + return -1; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); diff --git a/src/audio/netbsd/SDL_netbsdaudio.c b/src/audio/netbsd/SDL_netbsdaudio.c index c5f97eb10..ac2606302 100644 --- a/src/audio/netbsd/SDL_netbsdaudio.c +++ b/src/audio/netbsd/SDL_netbsdaudio.c @@ -216,7 +216,7 @@ static int NETBSDAUDIO_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } // Open the audio device; we hardcode the device path in `device->name` for lack of better info, so use that. @@ -294,7 +294,7 @@ static int NETBSDAUDIO_OpenDevice(SDL_AudioDevice *device) device->hidden->mixlen = device->buffer_size; device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->hidden->mixlen); if (!device->hidden->mixbuf) { - return SDL_OutOfMemory(); + return -1; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); } diff --git a/src/audio/openslES/SDL_openslES.c b/src/audio/openslES/SDL_openslES.c index 22bec9dd6..4253ebcad 100644 --- a/src/audio/openslES/SDL_openslES.c +++ b/src/audio/openslES/SDL_openslES.c @@ -600,7 +600,7 @@ static int OPENSLES_OpenDevice(SDL_AudioDevice *device) { device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } if (device->iscapture) { diff --git a/src/audio/pipewire/SDL_pipewire.c b/src/audio/pipewire/SDL_pipewire.c index bd4ee2ed0..00e469422 100644 --- a/src/audio/pipewire/SDL_pipewire.c +++ b/src/audio/pipewire/SDL_pipewire.c @@ -689,7 +689,6 @@ static void registry_event_global_callback(void *object, uint32_t id, uint32_t p node->userdata = io = SDL_calloc(1, sizeof(struct io_node) + desc_buffer_len + path_buffer_len); if (!io) { node_object_destroy(node); - SDL_OutOfMemory(); return; } @@ -1105,7 +1104,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device) priv = SDL_calloc(1, sizeof(struct SDL_PrivateAudioData)); device->hidden = priv; if (!priv) { - return SDL_OutOfMemory(); + return -1; } // Size of a single audio frame in bytes diff --git a/src/audio/ps2/SDL_ps2audio.c b/src/audio/ps2/SDL_ps2audio.c index fd64d86e1..0971031c5 100644 --- a/src/audio/ps2/SDL_ps2audio.c +++ b/src/audio/ps2/SDL_ps2audio.c @@ -31,7 +31,7 @@ static int PS2AUDIO_OpenDevice(SDL_AudioDevice *device) { device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } // These are the native supported audio PS2 configs diff --git a/src/audio/psp/SDL_pspaudio.c b/src/audio/psp/SDL_pspaudio.c index 057b4b14f..f2b771661 100644 --- a/src/audio/psp/SDL_pspaudio.c +++ b/src/audio/psp/SDL_pspaudio.c @@ -42,7 +42,7 @@ static int PSPAUDIO_OpenDevice(SDL_AudioDevice *device) { device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } // device only natively supports S16LSB diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c index b4fd97e5c..bf86b49ca 100644 --- a/src/audio/pulseaudio/SDL_pulseaudio.c +++ b/src/audio/pulseaudio/SDL_pulseaudio.c @@ -615,7 +615,7 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown h = device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } // Try for a closest match on audio format @@ -664,7 +664,7 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device) if (!iscapture) { h->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!h->mixbuf) { - return SDL_OutOfMemory(); + return -1; } SDL_memset(h->mixbuf, device->silence_value, device->buffer_size); } diff --git a/src/audio/qnx/SDL_qsa_audio.c b/src/audio/qnx/SDL_qsa_audio.c index 27e21d721..0e2d37cf4 100644 --- a/src/audio/qnx/SDL_qsa_audio.c +++ b/src/audio/qnx/SDL_qsa_audio.c @@ -206,7 +206,7 @@ static int QSA_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, (sizeof (struct SDL_PrivateAudioData))); if (device->hidden == NULL) { - return SDL_OutOfMemory(); + return -1; } // Initialize channel transfer parameters to default @@ -275,7 +275,7 @@ static int QSA_OpenDevice(SDL_AudioDevice *device) device->hidden->pcm_buf = (Uint8 *) SDL_malloc(device->buffer_size); if (device->hidden->pcm_buf == NULL) { - return SDL_OutOfMemory(); + return -1; } SDL_memset(device->hidden->pcm_buf, device->silence_value, device->buffer_size); diff --git a/src/audio/sndio/SDL_sndioaudio.c b/src/audio/sndio/SDL_sndioaudio.c index 970e2e907..59205889e 100644 --- a/src/audio/sndio/SDL_sndioaudio.c +++ b/src/audio/sndio/SDL_sndioaudio.c @@ -228,7 +228,7 @@ static int SNDIO_OpenDevice(SDL_AudioDevice *device) { device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } // !!! FIXME: we really should standardize this on a specific SDL hint. @@ -243,7 +243,7 @@ static int SNDIO_OpenDevice(SDL_AudioDevice *device) device->hidden->pfd = SDL_malloc(sizeof(struct pollfd) * SNDIO_sio_nfds(device->hidden->dev)); if (!device->hidden->pfd) { - return SDL_OutOfMemory(); + return -1; } struct sio_par par; @@ -308,7 +308,7 @@ static int SNDIO_OpenDevice(SDL_AudioDevice *device) // Allocate mixing buffer device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return SDL_OutOfMemory(); + return -1; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); diff --git a/src/audio/vita/SDL_vitaaudio.c b/src/audio/vita/SDL_vitaaudio.c index 7e7c60608..865752c2b 100644 --- a/src/audio/vita/SDL_vitaaudio.c +++ b/src/audio/vita/SDL_vitaaudio.c @@ -62,11 +62,10 @@ static int VITAAUD_OpenDevice(SDL_AudioDevice *device) const SDL_AudioFormat *closefmts; device->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc(sizeof(*device->hidden)); + SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(device->hidden, 0, sizeof(*device->hidden)); closefmts = SDL_ClosestAudioFormats(device->spec.format); while ((test_format = *(closefmts++)) != 0) { diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c index 938811a4a..294f6420b 100644 --- a/src/audio/wasapi/SDL_wasapi.c +++ b/src/audio/wasapi/SDL_wasapi.c @@ -104,7 +104,7 @@ int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, in ManagementThreadPendingTask *pending = SDL_calloc(1, sizeof(ManagementThreadPendingTask)); if (!pending) { - return SDL_OutOfMemory(); + return -1; } pending->fn = task; @@ -700,7 +700,7 @@ static int WASAPI_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return SDL_OutOfMemory(); + return -1; } else if (ActivateWasapiDevice(device) < 0) { return -1; // already set error. } diff --git a/src/core/linux/SDL_evdev.c b/src/core/linux/SDL_evdev.c index 829c7d864..c12fcf0bb 100644 --- a/src/core/linux/SDL_evdev.c +++ b/src/core/linux/SDL_evdev.c @@ -170,7 +170,7 @@ int SDL_EVDEV_Init(void) if (!_this) { _this = (SDL_EVDEV_PrivateData *)SDL_calloc(1, sizeof(*_this)); if (!_this) { - return SDL_OutOfMemory(); + return -1; } #ifdef SDL_USE_LIBUDEV @@ -644,7 +644,7 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class) item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data)); if (!item->touchscreen_data) { - return SDL_OutOfMemory(); + return -1; } ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name); @@ -656,7 +656,7 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class) item->touchscreen_data->name = SDL_strdup(name); if (!item->touchscreen_data->name) { SDL_free(item->touchscreen_data); - return SDL_OutOfMemory(); + return -1; } ret = ioctl(item->fd, EVIOCGABS(ABS_MT_SLOT), &abs_info); @@ -712,7 +712,7 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class) if (!item->touchscreen_data->slots) { SDL_free(item->touchscreen_data->name); SDL_free(item->touchscreen_data); - return SDL_OutOfMemory(); + return -1; } for (i = 0; i < item->touchscreen_data->max_slots; i++) { @@ -883,7 +883,7 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class) item = (SDL_evdevlist_item *)SDL_calloc(1, sizeof(SDL_evdevlist_item)); if (!item) { - return SDL_OutOfMemory(); + return -1; } item->fd = open(dev_path, O_RDONLY | O_NONBLOCK | O_CLOEXEC); @@ -896,7 +896,7 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class) if (!item->path) { close(item->fd); SDL_free(item); - return SDL_OutOfMemory(); + return -1; } item->udev_class = udev_class; diff --git a/src/core/linux/SDL_udev.c b/src/core/linux/SDL_udev.c index 903f27208..72a527e03 100644 --- a/src/core/linux/SDL_udev.c +++ b/src/core/linux/SDL_udev.c @@ -112,7 +112,7 @@ int SDL_UDEV_Init(void) if (!_this) { _this = (SDL_UDEV_PrivateData *)SDL_calloc(1, sizeof(*_this)); if (!_this) { - return SDL_OutOfMemory(); + return -1; } retval = SDL_UDEV_LoadLibrary(); @@ -518,7 +518,7 @@ int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb) SDL_UDEV_CallbackList *item; item = (SDL_UDEV_CallbackList *)SDL_calloc(1, sizeof(SDL_UDEV_CallbackList)); if (!item) { - return SDL_OutOfMemory(); + return -1; } item->callback = cb; diff --git a/src/core/windows/SDL_immdevice.c b/src/core/windows/SDL_immdevice.c index 629f4a181..fe2de5728 100644 --- a/src/core/windows/SDL_immdevice.c +++ b/src/core/windows/SDL_immdevice.c @@ -149,12 +149,10 @@ static SDL_AudioDevice *SDL_IMMDevice_Add(const SDL_bool iscapture, const char * // handle is freed by SDL_IMMDevice_FreeDeviceHandle! SDL_IMMDevice_HandleData *handle = SDL_malloc(sizeof(SDL_IMMDevice_HandleData)); if (!handle) { - SDL_OutOfMemory(); return NULL; } handle->immdevice_id = SDL_wcsdup(devid); if (!handle->immdevice_id) { - SDL_OutOfMemory(); SDL_free(handle); return NULL; } diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 5879629ba..040e5bdc8 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -105,7 +105,6 @@ void *SDL_AllocateEventMemory(size_t size) { void *memory = SDL_malloc(size); if (!memory) { - SDL_OutOfMemory(); return NULL; } @@ -126,7 +125,6 @@ void *SDL_AllocateEventMemory(size_t size) } else { SDL_free(memory); memory = NULL; - SDL_OutOfMemory(); } } SDL_UnlockMutex(SDL_event_memory_lock); @@ -1295,7 +1293,6 @@ int SDL_AddEventWatch(SDL_EventFilter filter, void *userdata) watcher->removed = SDL_FALSE; ++SDL_event_watchers_count; } else { - SDL_OutOfMemory(); result = -1; } } diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 6487ca181..eb9a863f6 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -489,7 +489,7 @@ int SDL_SetMouseSystemScale(int num_values, const float *values) v = (float *)SDL_realloc(mouse->system_scale_values, num_values * sizeof(*values)); if (!v) { - return SDL_OutOfMemory(); + return -1; } SDL_memcpy(v, values, num_values * sizeof(*values)); @@ -1300,9 +1300,6 @@ SDL_Cursor *SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y) cursor = mouse->CreateCursor(surface, hot_x, hot_y); } else { cursor = SDL_calloc(1, sizeof(*cursor)); - if (!cursor) { - SDL_OutOfMemory(); - } } if (cursor) { cursor->next = mouse->cursors; diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index 08e570909..2a38293fe 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -57,9 +57,7 @@ SDL_TouchID *SDL_GetTouchDevices(int *count) const int total = SDL_num_touch; SDL_TouchID *retval = (SDL_TouchID *) SDL_malloc(sizeof (SDL_TouchID) * (total + 1)); - if (!retval) { - SDL_OutOfMemory(); - } else { + if (retval) { for (int i = 0; i < total; i++) { retval[i] = SDL_touchDevices[i]->id; } @@ -169,7 +167,7 @@ int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name touchDevices = (SDL_Touch **)SDL_realloc(SDL_touchDevices, (SDL_num_touch + 1) * sizeof(*touchDevices)); if (!touchDevices) { - return SDL_OutOfMemory(); + return -1; } SDL_touchDevices = touchDevices; @@ -177,7 +175,7 @@ int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name SDL_touchDevices[index] = (SDL_Touch *)SDL_malloc(sizeof(*SDL_touchDevices[index])); if (!SDL_touchDevices[index]) { - return SDL_OutOfMemory(); + return -1; } /* Added touch to list */ @@ -202,12 +200,12 @@ static int SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float SDL_Finger **new_fingers; new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers + 1) * sizeof(*touch->fingers)); if (!new_fingers) { - return SDL_OutOfMemory(); + return -1; } touch->fingers = new_fingers; touch->fingers[touch->max_fingers] = (SDL_Finger *)SDL_malloc(sizeof(*finger)); if (!touch->fingers[touch->max_fingers]) { - return SDL_OutOfMemory(); + return -1; } touch->max_fingers++; } diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index a671c76f2..38aad554f 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -92,7 +92,7 @@ static int SDLCALL windows_file_open(SDL_RWops *context, const char *filename, c context->hidden.windowsio.buffer.data = (char *)SDL_malloc(READAHEAD_BUFFER_SIZE); if (!context->hidden.windowsio.buffer.data) { - return SDL_OutOfMemory(); + return -1; } #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) && !defined(__WINRT__) /* Do not open a dialog box if failure */ @@ -609,9 +609,7 @@ SDL_RWops *SDL_CreateRW(void) SDL_RWops *context; context = (SDL_RWops *)SDL_calloc(1, sizeof(*context)); - if (!context) { - SDL_OutOfMemory(); - } else { + if (context) { context->type = SDL_RWOPS_UNKNOWN; } return context; @@ -643,12 +641,10 @@ void *SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc) loading_chunks = SDL_TRUE; } if (size >= SDL_SIZE_MAX) { - SDL_OutOfMemory(); goto done; } data = (char *)SDL_malloc((size_t)(size + 1)); if (!data) { - SDL_OutOfMemory(); goto done; } @@ -665,7 +661,6 @@ void *SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc) if (!newdata) { SDL_free(data); data = NULL; - SDL_OutOfMemory(); goto done; } data = newdata; diff --git a/src/file/n3ds/SDL_rwopsromfs.c b/src/file/n3ds/SDL_rwopsromfs.c index a1bde5494..92d9a8141 100644 --- a/src/file/n3ds/SDL_rwopsromfs.c +++ b/src/file/n3ds/SDL_rwopsromfs.c @@ -78,7 +78,6 @@ FILE *TryOpenInRomfs(const char *file, const char *mode) char *prefixed_filepath = NULL; if (SDL_asprintf(&prefixed_filepath, "romfs:/%s", file) < 0) { - SDL_OutOfMemory(); return NULL; } diff --git a/src/filesystem/android/SDL_sysfilesystem.c b/src/filesystem/android/SDL_sysfilesystem.c index a287b005e..0fc466ffb 100644 --- a/src/filesystem/android/SDL_sysfilesystem.c +++ b/src/filesystem/android/SDL_sysfilesystem.c @@ -41,7 +41,6 @@ char *SDL_GetPrefPath(const char *org, const char *app) size_t pathlen = SDL_strlen(path) + 2; char *fullpath = (char *)SDL_malloc(pathlen); if (!fullpath) { - SDL_OutOfMemory(); return NULL; } SDL_snprintf(fullpath, pathlen, "%s/", path); diff --git a/src/filesystem/cocoa/SDL_sysfilesystem.m b/src/filesystem/cocoa/SDL_sysfilesystem.m index 0a78a2d9a..eb5ee9b85 100644 --- a/src/filesystem/cocoa/SDL_sysfilesystem.m +++ b/src/filesystem/cocoa/SDL_sysfilesystem.m @@ -52,9 +52,7 @@ char *SDL_GetBasePath(void) if (base) { const size_t len = SDL_strlen(base) + 2; retval = (char *)SDL_malloc(len); - if (retval == NULL) { - SDL_OutOfMemory(); - } else { + if (retval != NULL) { SDL_snprintf(retval, len, "%s/", base); } } @@ -105,9 +103,7 @@ char *SDL_GetPrefPath(const char *org, const char *app) if (base) { const size_t len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4; retval = (char *)SDL_malloc(len); - if (retval == NULL) { - SDL_OutOfMemory(); - } else { + if (retval != NULL) { char *ptr; if (*org) { SDL_snprintf(retval, len, "%s/%s/%s/", base, org, app); @@ -152,13 +148,7 @@ char *SDL_GetUserFolder(SDL_Folder folder) SDL_SetError("No $HOME environment variable available"); } - retval = SDL_strdup(base); - - if (!retval) { - SDL_OutOfMemory(); - } - - return retval; + return SDL_strdup(base); case SDL_FOLDER_DESKTOP: dir = NSDesktopDirectory; @@ -221,7 +211,6 @@ char *SDL_GetUserFolder(SDL_Folder folder) retval = SDL_strdup(base); if (retval == NULL) { - SDL_OutOfMemory(); return NULL; } diff --git a/src/filesystem/emscripten/SDL_sysfilesystem.c b/src/filesystem/emscripten/SDL_sysfilesystem.c index 5c87840b3..b22ee4ce5 100644 --- a/src/filesystem/emscripten/SDL_sysfilesystem.c +++ b/src/filesystem/emscripten/SDL_sysfilesystem.c @@ -53,7 +53,6 @@ char *SDL_GetPrefPath(const char *org, const char *app) len = SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3; retval = (char *)SDL_malloc(len); if (!retval) { - SDL_OutOfMemory(); return NULL; } @@ -86,7 +85,6 @@ char *SDL_GetPrefPath(const char *org, const char *app) char *SDL_GetUserFolder(SDL_Folder folder) { const char *home = NULL; - char *retval; if (folder != SDL_FOLDER_HOME) { SDL_SetError("Emscripten only supports the home folder"); @@ -99,13 +97,7 @@ char *SDL_GetUserFolder(SDL_Folder folder) return NULL; } - retval = SDL_strdup(home); - - if (!retval) { - SDL_OutOfMemory(); - } - - return retval; + return SDL_strdup(home); } #endif /* SDL_FILESYSTEM_EMSCRIPTEN */ diff --git a/src/filesystem/gdk/SDL_sysfilesystem.cpp b/src/filesystem/gdk/SDL_sysfilesystem.cpp index 3bbfca311..6794a31fe 100644 --- a/src/filesystem/gdk/SDL_sysfilesystem.cpp +++ b/src/filesystem/gdk/SDL_sysfilesystem.cpp @@ -46,7 +46,6 @@ SDL_GetBasePath(void) void *ptr = SDL_realloc(path, buflen * sizeof(CHAR)); if (!ptr) { SDL_free(path); - SDL_OutOfMemory(); return NULL; } diff --git a/src/filesystem/haiku/SDL_sysfilesystem.cc b/src/filesystem/haiku/SDL_sysfilesystem.cc index 9a5f2575c..d28baacef 100644 --- a/src/filesystem/haiku/SDL_sysfilesystem.cc +++ b/src/filesystem/haiku/SDL_sysfilesystem.cc @@ -52,7 +52,6 @@ char *SDL_GetBasePath(void) const size_t len = SDL_strlen(str); char *retval = (char *) SDL_malloc(len + 2); if (!retval) { - SDL_OutOfMemory(); return NULL; } @@ -83,9 +82,7 @@ char *SDL_GetPrefPath(const char *org, const char *app) } len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3; char *retval = (char *) SDL_malloc(len); - if (!retval) { - SDL_OutOfMemory(); - } else { + if (retval) { if (*org) { SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app); } else { @@ -110,25 +107,17 @@ char *SDL_GetUserFolder(SDL_Folder folder) switch (folder) { case SDL_FOLDER_HOME: - retval = SDL_strdup(home); - - if (!retval) { - SDL_OutOfMemory(); - } - - return retval; + return SDL_strdup(home); /* TODO: Is Haiku's desktop folder always ~/Desktop/ ? */ case SDL_FOLDER_DESKTOP: retval = (char *) SDL_malloc(SDL_strlen(home) + 10); - if (!retval) { - SDL_OutOfMemory(); + if (retval) { + SDL_strlcpy(retval, home, SDL_strlen(home) + 10); + SDL_strlcat(retval, "/Desktop/", SDL_strlen(home) + 10); } - SDL_strlcpy(retval, home, SDL_strlen(home) + 10); - SDL_strlcat(retval, "/Desktop/", SDL_strlen(home) + 10); - return retval; case SDL_FOLDER_DOCUMENTS: diff --git a/src/filesystem/n3ds/SDL_sysfilesystem.c b/src/filesystem/n3ds/SDL_sysfilesystem.c index 00ac71fc8..a4bea05c6 100644 --- a/src/filesystem/n3ds/SDL_sysfilesystem.c +++ b/src/filesystem/n3ds/SDL_sysfilesystem.c @@ -70,7 +70,6 @@ static char *MakePrefPath(const char *app) { char *pref_path; if (SDL_asprintf(&pref_path, "sdmc:/3ds/%s/", app) < 0) { - SDL_OutOfMemory(); return NULL; } return pref_path; diff --git a/src/filesystem/riscos/SDL_sysfilesystem.c b/src/filesystem/riscos/SDL_sysfilesystem.c index 842d62e38..83b676de2 100644 --- a/src/filesystem/riscos/SDL_sysfilesystem.c +++ b/src/filesystem/riscos/SDL_sysfilesystem.c @@ -42,7 +42,6 @@ static char *SDL_unixify_std(const char *ro_path, char *buffer, size_t buf_len, buffer = SDL_malloc(buf_len); if (!buffer) { - SDL_OutOfMemory(); return NULL; } } @@ -89,7 +88,6 @@ static char *canonicalisePath(const char *path, const char *pathVar) regs.r[5] = 1 - regs.r[5]; buf = SDL_malloc(regs.r[5]); if (!buf) { - SDL_OutOfMemory(); return NULL; } regs.r[2] = (int)buf; @@ -174,7 +172,6 @@ char *SDL_GetPrefPath(const char *org, const char *app) len = SDL_strlen(canon) + SDL_strlen(org) + SDL_strlen(app) + 4; dir = (char *)SDL_malloc(len); if (!dir) { - SDL_OutOfMemory(); SDL_free(canon); return NULL; } diff --git a/src/filesystem/unix/SDL_sysfilesystem.c b/src/filesystem/unix/SDL_sysfilesystem.c index 491f0f0d8..d288e9d75 100644 --- a/src/filesystem/unix/SDL_sysfilesystem.c +++ b/src/filesystem/unix/SDL_sysfilesystem.c @@ -48,7 +48,6 @@ static char *readSymLink(const char *path) while (1) { char *ptr = (char *)SDL_realloc(retval, (size_t)len); if (!ptr) { - SDL_OutOfMemory(); break; } @@ -85,7 +84,6 @@ static char *search_path_for_binary(const char *bin) envr = SDL_strdup(envr); if (!envr) { - SDL_OutOfMemory(); return NULL; } @@ -131,7 +129,6 @@ char *SDL_GetBasePath(void) if (sysctl(mib, SDL_arraysize(mib), fullpath, &buflen, NULL, 0) != -1) { retval = SDL_strdup(fullpath); if (!retval) { - SDL_OutOfMemory(); return NULL; } } @@ -145,14 +142,12 @@ char *SDL_GetBasePath(void) char *exe, *pwddst; char *realpathbuf = (char *)SDL_malloc(PATH_MAX + 1); if (!realpathbuf) { - SDL_OutOfMemory(); return NULL; } cmdline = SDL_malloc(len); if (!cmdline) { SDL_free(realpathbuf); - SDL_OutOfMemory(); return NULL; } @@ -228,7 +223,6 @@ char *SDL_GetBasePath(void) if ((path) && (path[0] == '/')) { /* must be absolute path... */ retval = SDL_strdup(path); if (!retval) { - SDL_OutOfMemory(); return NULL; } } @@ -302,7 +296,6 @@ char *SDL_GetPrefPath(const char *org, const char *app) len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3; retval = (char *)SDL_malloc(len); if (!retval) { - SDL_OutOfMemory(); return NULL; } @@ -541,13 +534,7 @@ char *SDL_GetUserFolder(SDL_Folder folder) return NULL; } - retval = SDL_strdup(param); - - if (!retval) { - SDL_OutOfMemory(); - } - - return retval; + return SDL_strdup(param); case SDL_FOLDER_DESKTOP: param = "DESKTOP"; diff --git a/src/filesystem/vita/SDL_sysfilesystem.c b/src/filesystem/vita/SDL_sysfilesystem.c index e06664908..83b842544 100644 --- a/src/filesystem/vita/SDL_sysfilesystem.c +++ b/src/filesystem/vita/SDL_sysfilesystem.c @@ -61,7 +61,6 @@ char *SDL_GetPrefPath(const char *org, const char *app) len += SDL_strlen(org) + SDL_strlen(app) + 3; retval = (char *)SDL_malloc(len); if (!retval) { - SDL_OutOfMemory(); return NULL; } diff --git a/src/filesystem/windows/SDL_sysfilesystem.c b/src/filesystem/windows/SDL_sysfilesystem.c index d31193af2..160d33087 100644 --- a/src/filesystem/windows/SDL_sysfilesystem.c +++ b/src/filesystem/windows/SDL_sysfilesystem.c @@ -53,7 +53,6 @@ char *SDL_GetBasePath(void) void *ptr = SDL_realloc(path, buflen * sizeof(WCHAR)); if (!ptr) { SDL_free(path); - SDL_OutOfMemory(); return NULL; } @@ -123,14 +122,12 @@ char *SDL_GetPrefPath(const char *org, const char *app) worg = WIN_UTF8ToStringW(org); if (!worg) { - SDL_OutOfMemory(); return NULL; } wapp = WIN_UTF8ToStringW(app); if (!wapp) { SDL_free(worg); - SDL_OutOfMemory(); return NULL; } diff --git a/src/filesystem/winrt/SDL_sysfilesystem.cpp b/src/filesystem/winrt/SDL_sysfilesystem.cpp index d442d2603..6cefbc049 100644 --- a/src/filesystem/winrt/SDL_sysfilesystem.cpp +++ b/src/filesystem/winrt/SDL_sysfilesystem.cpp @@ -131,7 +131,6 @@ SDL_GetBasePath(void) destPathLen = SDL_strlen(srcPath) + 2; destPath = (char *)SDL_malloc(destPathLen); if (!destPath) { - SDL_OutOfMemory(); return NULL; } @@ -178,14 +177,12 @@ SDL_GetPrefPath(const char *org, const char *app) worg = WIN_UTF8ToString(org); if (!worg) { - SDL_OutOfMemory(); return NULL; } wapp = WIN_UTF8ToString(app); if (!wapp) { SDL_free(worg); - SDL_OutOfMemory(); return NULL; } diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index ad70f274a..60dd37d34 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -125,7 +125,6 @@ SDL_Haptic *SDL_HapticOpen(int device_index) /* Create the haptic device */ haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic)); if (!haptic) { - SDL_OutOfMemory(); return NULL; } @@ -297,7 +296,6 @@ SDL_Haptic *SDL_HapticOpenFromJoystick(SDL_Joystick *joystick) /* Create the haptic device */ haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic)); if (!haptic) { - SDL_OutOfMemory(); SDL_UnlockJoysticks(); return NULL; } diff --git a/src/haptic/android/SDL_syshaptic.c b/src/haptic/android/SDL_syshaptic.c index b3d9b21eb..8a68cf795 100644 --- a/src/haptic/android/SDL_syshaptic.c +++ b/src/haptic/android/SDL_syshaptic.c @@ -107,7 +107,6 @@ static SDL_hapticlist_item *OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item * haptic->nplaying = haptic->neffects; haptic->effects = (struct haptic_effect *)SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); if (!haptic->effects) { - SDL_OutOfMemory(); return NULL; } SDL_memset(haptic->effects, 0, sizeof(struct haptic_effect) * haptic->neffects); diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c index c0583640a..44a85b383 100644 --- a/src/haptic/darwin/SDL_syshaptic.c +++ b/src/haptic/darwin/SDL_syshaptic.c @@ -473,13 +473,10 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic int ret2; /* Allocate the hwdata */ - haptic->hwdata = (struct haptic_hwdata *) - SDL_malloc(sizeof(*haptic->hwdata)); + haptic->hwdata = (struct haptic_hwdata *) SDL_calloc(1, sizeof(*haptic->hwdata)); if (!haptic->hwdata) { - SDL_OutOfMemory(); goto creat_err; } - SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); /* Open the device */ ret = FFCreateDevice(service, &haptic->hwdata->device); @@ -513,7 +510,6 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic haptic->effects = (struct haptic_effect *) SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); if (!haptic->effects) { - SDL_OutOfMemory(); goto open_err; } /* Clear the memory */ @@ -700,7 +696,7 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, SDL_HapticDirection *dir, int /* Has axes. */ rglDir = SDL_malloc(sizeof(LONG) * naxes); if (!rglDir) { - return SDL_OutOfMemory(); + return -1; } SDL_memset(rglDir, 0, sizeof(LONG) * naxes); effect->rglDirection = rglDir; @@ -771,11 +767,10 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe dest->dwFlags = FFEFF_OBJECTOFFSETS; /* Seems obligatory. */ /* Envelope. */ - envelope = SDL_malloc(sizeof(FFENVELOPE)); + envelope = SDL_calloc(1, sizeof(FFENVELOPE)); if (!envelope) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(envelope, 0, sizeof(FFENVELOPE)); dest->lpEnvelope = envelope; envelope->dwSize = sizeof(FFENVELOPE); /* Always should be this. */ @@ -788,7 +783,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) { - return SDL_OutOfMemory(); + return -1; } axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */ if (dest->cAxes > 1) { @@ -804,11 +799,10 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe switch (src->type) { case SDL_HAPTIC_CONSTANT: hap_constant = &src->constant; - constant = SDL_malloc(sizeof(FFCONSTANTFORCE)); + constant = SDL_calloc(1, sizeof(FFCONSTANTFORCE)); if (!constant) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE)); /* Specifics */ constant->lMagnitude = CONVERT(hap_constant->level); @@ -846,11 +840,10 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe case SDL_HAPTIC_SAWTOOTHUP: case SDL_HAPTIC_SAWTOOTHDOWN: hap_periodic = &src->periodic; - periodic = SDL_malloc(sizeof(FFPERIODIC)); + periodic = SDL_calloc(1, sizeof(FFPERIODIC)); if (!periodic) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(periodic, 0, sizeof(FFPERIODIC)); /* Specifics */ periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude)); @@ -891,11 +884,10 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe case SDL_HAPTIC_FRICTION: hap_condition = &src->condition; if (dest->cAxes > 0) { - condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes); + condition = SDL_calloc(dest->cAxes, sizeof(FFCONDITION)); if (!condition) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(condition, 0, sizeof(FFCONDITION)); /* Specifics */ for (i = 0; i < dest->cAxes; i++) { @@ -934,11 +926,10 @@ 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)); + ramp = SDL_calloc(1, sizeof(FFRAMPFORCE)); if (!ramp) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(ramp, 0, sizeof(FFRAMPFORCE)); /* Specifics */ ramp->lStart = CONVERT(hap_ramp->start); @@ -972,11 +963,10 @@ 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)); + custom = SDL_calloc(1, sizeof(FFCUSTOMFORCE)); if (!custom) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE)); /* Specifics */ custom->cChannels = hap_custom->channels; @@ -1107,9 +1097,8 @@ 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)); + SDL_calloc(1, sizeof(struct haptic_hweffect)); if (!effect->hweffect) { - SDL_OutOfMemory(); goto err_hweffect; } diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index 00e60411b..0649ce37c 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -375,12 +375,10 @@ static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd) { /* Allocate the hwdata */ haptic->hwdata = (struct haptic_hwdata *) - SDL_malloc(sizeof(*haptic->hwdata)); + SDL_calloc(1, sizeof(*haptic->hwdata)); if (!haptic->hwdata) { - SDL_OutOfMemory(); goto open_err; } - SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); /* Set the data. */ haptic->hwdata->fd = fd; @@ -397,7 +395,6 @@ static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd) haptic->effects = (struct haptic_effect *) SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); if (!haptic->effects) { - SDL_OutOfMemory(); goto open_err; } /* Clear the memory */ @@ -903,9 +900,9 @@ 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)); + SDL_calloc(1, sizeof(struct haptic_hweffect)); if (!effect->hweffect) { - return SDL_OutOfMemory(); + return -1; } /* Prepare the ff_effect */ diff --git a/src/haptic/windows/SDL_dinputhaptic.c b/src/haptic/windows/SDL_dinputhaptic.c index a1225dd67..45214ddcd 100644 --- a/src/haptic/windows/SDL_dinputhaptic.c +++ b/src/haptic/windows/SDL_dinputhaptic.c @@ -167,7 +167,7 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance) item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item)); if (!item) { - return SDL_OutOfMemory(); + return -1; } item->name = WIN_StringToUTF8(pdidInstance->tszProductName); @@ -286,11 +286,10 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI DIPROPDWORD dipdw; /* Allocate the hwdata */ - haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata)); + haptic->hwdata = (struct haptic_hwdata *)SDL_calloc(1, sizeof(*haptic->hwdata)); if (!haptic->hwdata) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); /* We'll use the device8 from now on. */ haptic->hwdata->device = device8; @@ -402,7 +401,6 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI haptic->effects = (struct haptic_effect *) SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); if (!haptic->effects) { - SDL_OutOfMemory(); goto acquire_err; } /* Clear the memory */ @@ -541,7 +539,7 @@ static int SDL_SYS_SetDirection(DIEFFECT *effect, SDL_HapticDirection *dir, int /* Has axes. */ rglDir = SDL_malloc(sizeof(LONG) * naxes); if (!rglDir) { - return SDL_OutOfMemory(); + return -1; } SDL_memset(rglDir, 0, sizeof(LONG) * naxes); effect->rglDirection = rglDir; @@ -613,11 +611,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, dest->dwFlags = DIEFF_OBJECTOFFSETS; /* Seems obligatory. */ /* Envelope. */ - envelope = SDL_malloc(sizeof(DIENVELOPE)); + envelope = SDL_calloc(1, sizeof(DIENVELOPE)); if (!envelope) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(envelope, 0, sizeof(DIENVELOPE)); dest->lpEnvelope = envelope; envelope->dwSize = sizeof(DIENVELOPE); /* Always should be this. */ @@ -630,7 +627,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, if (dest->cAxes > 0) { axes = SDL_malloc(sizeof(DWORD) * dest->cAxes); if (!axes) { - return SDL_OutOfMemory(); + return -1; } axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */ if (dest->cAxes > 1) { @@ -646,11 +643,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, switch (src->type) { case SDL_HAPTIC_CONSTANT: hap_constant = &src->constant; - constant = SDL_malloc(sizeof(DICONSTANTFORCE)); + constant = SDL_calloc(1, sizeof(DICONSTANTFORCE)); if (!constant) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(constant, 0, sizeof(DICONSTANTFORCE)); /* Specifics */ constant->lMagnitude = CONVERT(hap_constant->level); @@ -688,11 +684,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, case SDL_HAPTIC_SAWTOOTHUP: case SDL_HAPTIC_SAWTOOTHDOWN: hap_periodic = &src->periodic; - periodic = SDL_malloc(sizeof(DIPERIODIC)); + periodic = SDL_calloc(1, sizeof(DIPERIODIC)); if (!periodic) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(periodic, 0, sizeof(DIPERIODIC)); /* Specifics */ periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude)); @@ -732,11 +727,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, case SDL_HAPTIC_INERTIA: case SDL_HAPTIC_FRICTION: hap_condition = &src->condition; - condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes); + condition = SDL_calloc(dest->cAxes, sizeof(DICONDITION)); if (!condition) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(condition, 0, sizeof(DICONDITION)); /* Specifics */ for (i = 0; i < (int)dest->cAxes; i++) { @@ -773,11 +767,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, case SDL_HAPTIC_RAMP: hap_ramp = &src->ramp; - ramp = SDL_malloc(sizeof(DIRAMPFORCE)); + ramp = SDL_calloc(1, sizeof(DIRAMPFORCE)); if (!ramp) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(ramp, 0, sizeof(DIRAMPFORCE)); /* Specifics */ ramp->lStart = CONVERT(hap_ramp->start); @@ -811,11 +804,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, case SDL_HAPTIC_CUSTOM: hap_custom = &src->custom; - custom = SDL_malloc(sizeof(DICUSTOMFORCE)); + custom = SDL_calloc(1, sizeof(DICUSTOMFORCE)); if (!custom) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(custom, 0, sizeof(DICUSTOMFORCE)); /* Specifics */ custom->cChannels = hap_custom->channels; diff --git a/src/haptic/windows/SDL_windowshaptic.c b/src/haptic/windows/SDL_windowshaptic.c index 771ba012b..fae8542b4 100644 --- a/src/haptic/windows/SDL_windowshaptic.c +++ b/src/haptic/windows/SDL_windowshaptic.c @@ -291,13 +291,10 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, int result; /* Alloc the effect. */ - effect->hweffect = (struct haptic_hweffect *) - SDL_malloc(sizeof(struct haptic_hweffect)); + effect->hweffect = (struct haptic_hweffect *) SDL_calloc(1, sizeof(struct haptic_hweffect)); if (!effect->hweffect) { - SDL_OutOfMemory(); return -1; } - SDL_zerop(effect->hweffect); if (haptic->hwdata->bXInputHaptic) { result = SDL_XINPUT_HapticNewEffect(haptic, effect, base); diff --git a/src/haptic/windows/SDL_xinputhaptic.c b/src/haptic/windows/SDL_xinputhaptic.c index 961f29407..b84c2eadd 100644 --- a/src/haptic/windows/SDL_xinputhaptic.c +++ b/src/haptic/windows/SDL_xinputhaptic.c @@ -78,13 +78,11 @@ int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid) return -1; /* no force feedback on this device. */ } - item = (SDL_hapticlist_item *)SDL_malloc(sizeof(SDL_hapticlist_item)); + item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item)); if (!item) { - return SDL_OutOfMemory(); + return -1; } - SDL_zerop(item); - /* !!! FIXME: I'm not bothering to query for a real name right now (can we even?) */ { char buf[64]; @@ -174,19 +172,18 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us haptic->effects = (struct haptic_effect *) SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); if (!haptic->effects) { - return SDL_OutOfMemory(); + return -1; } /* Clear the memory */ SDL_memset(haptic->effects, 0, sizeof(struct haptic_effect) * haptic->neffects); - haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata)); + haptic->hwdata = (struct haptic_hwdata *)SDL_calloc(1, sizeof(*haptic->hwdata)); if (!haptic->hwdata) { SDL_free(haptic->effects); haptic->effects = NULL; - return SDL_OutOfMemory(); + return -1; } - SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); haptic->hwdata->bXInputHaptic = 1; haptic->hwdata->userid = userid; diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c index 8347857e2..d7fc41028 100644 --- a/src/joystick/SDL_gamepad.c +++ b/src/joystick/SDL_gamepad.c @@ -1434,7 +1434,6 @@ static char *SDL_PrivateGetGamepadGUIDFromMappingString(const char *pMapping) if (pFirstComma) { char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1); if (!pchGUID) { - SDL_OutOfMemory(); return NULL; } SDL_memcpy(pchGUID, pMapping, pFirstComma - pMapping); @@ -1483,7 +1482,6 @@ static char *SDL_PrivateGetGamepadNameFromMappingString(const char *pMapping) pchName = SDL_malloc(pSecondComma - pFirstComma); if (!pchName) { - SDL_OutOfMemory(); return NULL; } SDL_memcpy(pchName, pFirstComma + 1, pSecondComma - pFirstComma); @@ -1620,7 +1618,6 @@ static GamepadMapping_t *SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, co PopMappingChangeTracking(); SDL_free(pchName); SDL_free(pchMapping); - SDL_OutOfMemory(); return NULL; } /* Clear the CRC, we've already added it to the mapping */ @@ -2032,7 +2029,6 @@ static char *CreateMappingString(GamepadMapping_t *mapping, SDL_JoystickGUID gui pMappingString = SDL_malloc(needed); if (!pMappingString) { - SDL_OutOfMemory(); return NULL; } @@ -2082,7 +2078,6 @@ char **SDL_GetGamepadMappings(int *count) mappings = (char **) SDL_calloc(num_mappings + 1, sizeof (char *)); if (!mappings) { failed = SDL_TRUE; - SDL_OutOfMemory(); } else { size_t i = 0; for (GamepadMapping_t *mapping = s_pSupportedGamepads; mapping; mapping = mapping->next) { @@ -2107,9 +2102,7 @@ char **SDL_GetGamepadMappings(int *count) if (!failed) { retval = (char **) SDL_malloc(final_allocation); - if (!retval) { - SDL_OutOfMemory(); - } else { + if (retval) { final_allocation -= (sizeof (char *) * num_mappings + 1); char *strptr = (char *) (retval + (num_mappings + 1)); for (int i = 0; i < num_mappings; i++) { @@ -2431,19 +2424,10 @@ char *SDL_GetGamepadInstanceMapping(SDL_JoystickID instance_id) { GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id); if (mapping) { - SDL_JoystickGUID guid; char pchGUID[33]; - size_t needed; - guid = SDL_GetJoystickInstanceGUID(instance_id); + const SDL_JoystickGUID guid = SDL_GetJoystickInstanceGUID(instance_id); SDL_GetJoystickGUIDString(guid, pchGUID, sizeof(pchGUID)); - /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */ - needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1; - retval = (char *)SDL_malloc(needed); - if (retval) { - (void)SDL_snprintf(retval, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping); - } else { - SDL_OutOfMemory(); - } + SDL_asprintf(&retval, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping); } } SDL_UnlockJoysticks(); @@ -2595,7 +2579,6 @@ SDL_Gamepad *SDL_OpenGamepad(SDL_JoystickID instance_id) /* Create and initialize the gamepad */ gamepad = (SDL_Gamepad *)SDL_calloc(1, sizeof(*gamepad)); if (!gamepad) { - SDL_OutOfMemory(); SDL_UnlockJoysticks(); return NULL; } @@ -2611,7 +2594,6 @@ SDL_Gamepad *SDL_OpenGamepad(SDL_JoystickID instance_id) if (gamepad->joystick->naxes) { gamepad->last_match_axis = (SDL_GamepadBinding **)SDL_calloc(gamepad->joystick->naxes, sizeof(*gamepad->last_match_axis)); if (!gamepad->last_match_axis) { - SDL_OutOfMemory(); SDL_CloseJoystick(gamepad->joystick); SDL_free(gamepad); SDL_UnlockJoysticks(); @@ -2621,7 +2603,6 @@ SDL_Gamepad *SDL_OpenGamepad(SDL_JoystickID instance_id) if (gamepad->joystick->nhats) { gamepad->last_hat_mask = (Uint8 *)SDL_calloc(gamepad->joystick->nhats, sizeof(*gamepad->last_hat_mask)); if (!gamepad->last_hat_mask) { - SDL_OutOfMemory(); SDL_CloseJoystick(gamepad->joystick); SDL_free(gamepad->last_match_axis); SDL_free(gamepad); @@ -3442,8 +3423,6 @@ SDL_GamepadBinding **SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count) if (count) { *count = gamepad->num_bindings; } - } else { - SDL_OutOfMemory(); } } SDL_UnlockJoysticks(); diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index f26c3db20..cc0ca88d3 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -270,7 +270,6 @@ static SDL_bool SDL_SetJoystickIDForPlayerIndex(int player_index, SDL_JoystickID 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)); if (!new_players) { - SDL_OutOfMemory(); return SDL_FALSE; } @@ -403,8 +402,6 @@ SDL_JoystickID *SDL_GetJoysticks(int *count) if (count) { *count = 0; } - - SDL_OutOfMemory(); } } SDL_UnlockJoysticks(); @@ -755,7 +752,6 @@ SDL_Joystick *SDL_OpenJoystick(SDL_JoystickID instance_id) /* Create and initialize the joystick */ joystick = (SDL_Joystick *)SDL_calloc(sizeof(*joystick), 1); if (!joystick) { - SDL_OutOfMemory(); SDL_UnlockJoysticks(); return NULL; } @@ -798,7 +794,6 @@ SDL_Joystick *SDL_OpenJoystick(SDL_JoystickID instance_id) joystick->buttons = (Uint8 *)SDL_calloc(joystick->nbuttons, sizeof(Uint8)); } if (((joystick->naxes > 0) && !joystick->axes) || ((joystick->nhats > 0) && !joystick->hats) || ((joystick->nbuttons > 0) && !joystick->buttons)) { - SDL_OutOfMemory(); SDL_CloseJoystick(joystick); SDL_UnlockJoysticks(); return NULL; diff --git a/src/joystick/apple/SDL_mfijoystick.m b/src/joystick/apple/SDL_mfijoystick.m index 1b54bf46a..b8e6da62c 100644 --- a/src/joystick/apple/SDL_mfijoystick.m +++ b/src/joystick/apple/SDL_mfijoystick.m @@ -1165,7 +1165,6 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick) int button_count = 0; if (buttons == NULL) { - SDL_OutOfMemory(); return; } @@ -1222,7 +1221,6 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick) int button_count = 0; if (buttons == NULL) { - SDL_OutOfMemory(); return; } diff --git a/src/joystick/bsd/SDL_bsdjoystick.c b/src/joystick/bsd/SDL_bsdjoystick.c index 452228907..fc97c5d49 100644 --- a/src/joystick/bsd/SDL_bsdjoystick.c +++ b/src/joystick/bsd/SDL_bsdjoystick.c @@ -270,7 +270,6 @@ CreateHwData(const char *path) SDL_calloc(1, sizeof(struct joystick_hwdata)); if (!hw) { close(fd); - SDL_OutOfMemory(); return NULL; } hw->fd = fd; @@ -794,7 +793,7 @@ static int report_alloc(struct report *r, struct report_desc *rd, int repind) r->size); #endif if (!r->buf) { - return SDL_OutOfMemory(); + return -1; } } else { r->buf = NULL; diff --git a/src/joystick/darwin/SDL_iokitjoystick.c b/src/joystick/darwin/SDL_iokitjoystick.c index 50cb2e107..b6bc97fd7 100644 --- a/src/joystick/darwin/SDL_iokitjoystick.c +++ b/src/joystick/darwin/SDL_iokitjoystick.c @@ -529,7 +529,6 @@ static void JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender device = (recDevice *)SDL_calloc(1, sizeof(recDevice)); if (!device) { - SDL_OutOfMemory(); return; } @@ -834,7 +833,7 @@ static int DARWIN_JoystickInitRumble(recDevice *device, Sint16 magnitude) /* Create the effect */ device->ffeffect = CreateRumbleEffectData(magnitude); if (!device->ffeffect) { - return SDL_OutOfMemory(); + return -1; } result = FFDeviceCreateEffect(device->ffdevice, kFFEffectType_Sine_ID, diff --git a/src/joystick/haiku/SDL_haikujoystick.cc b/src/joystick/haiku/SDL_haikujoystick.cc index 5c07affb2..cfdca6a04 100644 --- a/src/joystick/haiku/SDL_haikujoystick.cc +++ b/src/joystick/haiku/SDL_haikujoystick.cc @@ -129,12 +129,10 @@ extern "C" /* Create the joystick data structure */ joystick->instance_id = device_index; - joystick->hwdata = (struct joystick_hwdata *) - SDL_malloc(sizeof(*joystick->hwdata)); + joystick->hwdata = (struct joystick_hwdata *) SDL_calloc(1, sizeof(*joystick->hwdata)); if (joystick->hwdata == NULL) { - return SDL_OutOfMemory(); + return -1; } - SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); stick = new BJoystick; joystick->hwdata->stick = stick; @@ -152,13 +150,11 @@ extern "C" joystick->naxes = stick->CountAxes(); joystick->nhats = stick->CountHats(); - joystick->hwdata->new_axes = (int16 *) - SDL_malloc(joystick->naxes * sizeof(int16)); - joystick->hwdata->new_hats = (uint8 *) - SDL_malloc(joystick->nhats * sizeof(uint8)); + joystick->hwdata->new_axes = (int16 *) SDL_calloc(joystick->naxes, sizeof(int16)); + joystick->hwdata->new_hats = (uint8 *) SDL_calloc(joystick->nhats, sizeof(uint8)); if (!joystick->hwdata->new_hats || !joystick->hwdata->new_axes) { HAIKU_JoystickClose(joystick); - return SDL_OutOfMemory(); + return -1; } /* We're done! */ diff --git a/src/joystick/hidapi/SDL_hidapi_gamecube.c b/src/joystick/hidapi/SDL_hidapi_gamecube.c index 9b8f97c17..8ca952cf2 100644 --- a/src/joystick/hidapi/SDL_hidapi_gamecube.c +++ b/src/joystick/hidapi/SDL_hidapi_gamecube.c @@ -115,7 +115,6 @@ static SDL_bool HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverGameCube_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } device->context = ctx; diff --git a/src/joystick/hidapi/SDL_hidapi_luna.c b/src/joystick/hidapi/SDL_hidapi_luna.c index 57f2a11a6..4e02b5f1a 100644 --- a/src/joystick/hidapi/SDL_hidapi_luna.c +++ b/src/joystick/hidapi/SDL_hidapi_luna.c @@ -73,7 +73,6 @@ static SDL_bool HIDAPI_DriverLuna_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverLuna_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } device->context = ctx; diff --git a/src/joystick/hidapi/SDL_hidapi_ps3.c b/src/joystick/hidapi/SDL_hidapi_ps3.c index eb49d8018..7ff706eb0 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps3.c +++ b/src/joystick/hidapi/SDL_hidapi_ps3.c @@ -135,7 +135,6 @@ static SDL_bool HIDAPI_DriverPS3_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverPS3_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } ctx->device = device; @@ -605,7 +604,6 @@ static SDL_bool HIDAPI_DriverPS3ThirdParty_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverPS3_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } ctx->device = device; diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c index a5e9cb0a3..3dc237213 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c @@ -277,7 +277,6 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverPS4_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } ctx->device = device; diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c index 4e71f95c6..b27f7029c 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps5.c +++ b/src/joystick/hidapi/SDL_hidapi_ps5.c @@ -376,7 +376,6 @@ static SDL_bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverPS5_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } ctx->device = device; diff --git a/src/joystick/hidapi/SDL_hidapi_rumble.c b/src/joystick/hidapi/SDL_hidapi_rumble.c index b29088cd1..8a246861f 100644 --- a/src/joystick/hidapi/SDL_hidapi_rumble.c +++ b/src/joystick/hidapi/SDL_hidapi_rumble.c @@ -216,7 +216,7 @@ int SDL_HIDAPI_SendRumbleWithCallbackAndUnlock(SDL_HIDAPI_Device *device, const request = (SDL_HIDAPI_RumbleRequest *)SDL_calloc(1, sizeof(*request)); if (!request) { SDL_HIDAPI_UnlockRumble(); - return SDL_OutOfMemory(); + return -1; } request->device = device; SDL_memcpy(request->data, data, size); diff --git a/src/joystick/hidapi/SDL_hidapi_shield.c b/src/joystick/hidapi/SDL_hidapi_shield.c index 5821c2d6f..71ee72c76 100644 --- a/src/joystick/hidapi/SDL_hidapi_shield.c +++ b/src/joystick/hidapi/SDL_hidapi_shield.c @@ -115,7 +115,6 @@ static SDL_bool HIDAPI_DriverShield_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverShield_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } device->context = ctx; diff --git a/src/joystick/hidapi/SDL_hidapi_stadia.c b/src/joystick/hidapi/SDL_hidapi_stadia.c index b5959cbb5..e4883862c 100644 --- a/src/joystick/hidapi/SDL_hidapi_stadia.c +++ b/src/joystick/hidapi/SDL_hidapi_stadia.c @@ -70,7 +70,6 @@ static SDL_bool HIDAPI_DriverStadia_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverStadia_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } device->context = ctx; diff --git a/src/joystick/hidapi/SDL_hidapi_steam.c b/src/joystick/hidapi/SDL_hidapi_steam.c index 5fc99fbef..aa6f18fff 100644 --- a/src/joystick/hidapi/SDL_hidapi_steam.c +++ b/src/joystick/hidapi/SDL_hidapi_steam.c @@ -974,7 +974,6 @@ static SDL_bool HIDAPI_DriverSteam_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverSteam_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } device->context = ctx; diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c index db52c6f23..5a4b109df 100644 --- a/src/joystick/hidapi/SDL_hidapi_switch.c +++ b/src/joystick/hidapi/SDL_hidapi_switch.c @@ -1246,7 +1246,6 @@ static SDL_bool HIDAPI_DriverSwitch_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverSwitch_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } ctx->device = device; diff --git a/src/joystick/hidapi/SDL_hidapi_wii.c b/src/joystick/hidapi/SDL_hidapi_wii.c index 4a529de76..423835e62 100644 --- a/src/joystick/hidapi/SDL_hidapi_wii.c +++ b/src/joystick/hidapi/SDL_hidapi_wii.c @@ -719,7 +719,6 @@ static SDL_bool HIDAPI_DriverWii_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverWii_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } ctx->device = device; diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360.c b/src/joystick/hidapi/SDL_hidapi_xbox360.c index bd9565303..3a7b3accc 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c @@ -140,7 +140,6 @@ static SDL_bool HIDAPI_DriverXbox360_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverXbox360_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } ctx->device = device; diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360w.c b/src/joystick/hidapi/SDL_hidapi_xbox360w.c index 954e16c09..a58c729e9 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360w.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360w.c @@ -132,7 +132,6 @@ static SDL_bool HIDAPI_DriverXbox360W_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverXbox360W_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } ctx->device = device; diff --git a/src/joystick/hidapi/SDL_hidapi_xboxone.c b/src/joystick/hidapi/SDL_hidapi_xboxone.c index d21881548..5cf5deda8 100644 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c @@ -360,7 +360,6 @@ static SDL_bool HIDAPI_DriverXboxOne_InitDevice(SDL_HIDAPI_Device *device) ctx = (SDL_DriverXboxOne_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { - SDL_OutOfMemory(); return SDL_FALSE; } ctx->device = device; diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index be3eb2e92..037651eca 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -1435,7 +1435,7 @@ static int HIDAPI_JoystickOpen(SDL_Joystick *joystick, int device_index) hwdata = (struct joystick_hwdata *)SDL_calloc(1, sizeof(*hwdata)); if (!hwdata) { - return SDL_OutOfMemory(); + return -1; } hwdata->device = device; diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 8a3dc2e16..9b8a85f26 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -1381,7 +1381,7 @@ static int PrepareJoystickHwdata(SDL_Joystick *joystick, SDL_joylist_item *item, if (fd_sensor >= 0) { close(fd_sensor); } - return SDL_OutOfMemory(); + return -1; } /* Set the joystick to non-blocking read mode */ @@ -1471,7 +1471,7 @@ static int LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index) joystick->hwdata = (struct joystick_hwdata *) SDL_calloc(1, sizeof(*joystick->hwdata)); if (!joystick->hwdata) { - return SDL_OutOfMemory(); + return -1; } item_sensor = GetSensor(item); @@ -2147,7 +2147,6 @@ static SDL_bool LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMap a fake SDL_Joystick object to do so. */ joystick = (SDL_Joystick *)SDL_calloc(sizeof(*joystick), 1); if (!joystick) { - SDL_OutOfMemory(); return SDL_FALSE; } joystick->magic = &SDL_joystick_magic; @@ -2157,7 +2156,6 @@ static SDL_bool LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMap SDL_calloc(1, sizeof(*joystick->hwdata)); if (!joystick->hwdata) { SDL_free(joystick); - SDL_OutOfMemory(); return SDL_FALSE; } diff --git a/src/joystick/virtual/SDL_virtualjoystick.c b/src/joystick/virtual/SDL_virtualjoystick.c index b6dbb5c41..23519e53b 100644 --- a/src/joystick/virtual/SDL_virtualjoystick.c +++ b/src/joystick/virtual/SDL_virtualjoystick.c @@ -125,7 +125,7 @@ SDL_JoystickID SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *des hwdata = SDL_calloc(1, sizeof(joystick_hwdata)); if (!hwdata) { VIRTUAL_FreeHWData(hwdata); - return SDL_OutOfMemory(); + return -1; } SDL_memcpy(&hwdata->desc, desc, sizeof(*desc)); @@ -210,7 +210,7 @@ SDL_JoystickID SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *des hwdata->axes = SDL_calloc(hwdata->desc.naxes, sizeof(Sint16)); if (!hwdata->axes) { VIRTUAL_FreeHWData(hwdata); - return SDL_OutOfMemory(); + return -1; } /* Trigger axes are at minimum value at rest */ @@ -225,14 +225,14 @@ SDL_JoystickID SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *des hwdata->buttons = SDL_calloc(hwdata->desc.nbuttons, sizeof(Uint8)); if (!hwdata->buttons) { VIRTUAL_FreeHWData(hwdata); - return SDL_OutOfMemory(); + return -1; } } if (hwdata->desc.nhats > 0) { hwdata->hats = SDL_calloc(hwdata->desc.nhats, sizeof(Uint8)); if (!hwdata->hats) { VIRTUAL_FreeHWData(hwdata); - return SDL_OutOfMemory(); + return -1; } } diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c index 56f844f22..f19bba852 100644 --- a/src/joystick/windows/SDL_dinputjoystick.c +++ b/src/joystick/windows/SDL_dinputjoystick.c @@ -878,7 +878,7 @@ static int SDL_DINPUT_JoystickInitRumble(SDL_Joystick *joystick, Sint16 magnitud /* Create the effect */ joystick->hwdata->ffeffect = CreateRumbleEffectData(magnitude); if (!joystick->hwdata->ffeffect) { - return SDL_OutOfMemory(); + return -1; } result = IDirectInputDevice8_CreateEffect(joystick->hwdata->InputDevice, &GUID_Sine, diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c index 3fd7b7fcf..3302e873e 100644 --- a/src/joystick/windows/SDL_rawinputjoystick.c +++ b/src/joystick/windows/SDL_rawinputjoystick.c @@ -618,12 +618,12 @@ static int RAWINPUT_UpdateWindowsGamingInput() WindowsGamingInputGamepadState **new_per_gamepad; gamepad_state = SDL_calloc(1, sizeof(*gamepad_state)); if (!gamepad_state) { - return SDL_OutOfMemory(); + return -1; } new_per_gamepad = SDL_realloc(wgi_state.per_gamepad, sizeof(wgi_state.per_gamepad[0]) * (wgi_state.per_gamepad_count + 1)); if (!new_per_gamepad) { SDL_free(gamepad_state); - return SDL_OutOfMemory(); + return -1; } wgi_state.per_gamepad = new_per_gamepad; wgi_state.per_gamepad_count++; @@ -1227,7 +1227,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) ctx = (RAWINPUT_DeviceContext *)SDL_calloc(1, sizeof(RAWINPUT_DeviceContext)); if (!ctx) { - return SDL_OutOfMemory(); + return -1; } joystick->hwdata = ctx; @@ -1259,7 +1259,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) ctx->data = (HIDP_DATA *)SDL_malloc(ctx->max_data_length * sizeof(*ctx->data)); if (!ctx->data) { RAWINPUT_JoystickClose(joystick); - return SDL_OutOfMemory(); + return -1; } if (SDL_HidP_GetCaps(ctx->preparsed_data, &caps) != HIDP_STATUS_SUCCESS) { @@ -1304,7 +1304,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) ctx->button_indices = (USHORT *)SDL_malloc(joystick->nbuttons * sizeof(*ctx->button_indices)); if (!ctx->button_indices) { RAWINPUT_JoystickClose(joystick); - return SDL_OutOfMemory(); + return -1; } for (i = 0; i < caps.NumberInputButtonCaps; ++i) { @@ -1357,7 +1357,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) ctx->axis_indices = (USHORT *)SDL_malloc(joystick->naxes * sizeof(*ctx->axis_indices)); if (!ctx->axis_indices) { RAWINPUT_JoystickClose(joystick); - return SDL_OutOfMemory(); + return -1; } for (i = 0; i < caps.NumberInputValueCaps; ++i) { @@ -1390,7 +1390,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) ctx->hat_indices = (USHORT *)SDL_malloc(joystick->nhats * sizeof(*ctx->hat_indices)); if (!ctx->hat_indices) { RAWINPUT_JoystickClose(joystick); - return SDL_OutOfMemory(); + return -1; } for (i = 0; i < caps.NumberInputValueCaps; ++i) { diff --git a/src/joystick/windows/SDL_windows_gaming_input.c b/src/joystick/windows/SDL_windows_gaming_input.c index 5f4ddab20..f0ee81d22 100644 --- a/src/joystick/windows/SDL_windows_gaming_input.c +++ b/src/joystick/windows/SDL_windows_gaming_input.c @@ -128,7 +128,6 @@ static SDL_bool SDL_IsXInputDevice(Uint16 vendor, Uint16 product) raw_devices = (PRAWINPUTDEVICELIST)SDL_malloc(sizeof(RAWINPUTDEVICELIST) * raw_device_count); if (!raw_devices) { - SDL_OutOfMemory(); return SDL_FALSE; } @@ -720,7 +719,7 @@ static int WGI_JoystickOpen(SDL_Joystick *joystick, int device_index) hwdata = (struct joystick_hwdata *)SDL_calloc(1, sizeof(*hwdata)); if (!hwdata) { - return SDL_OutOfMemory(); + return -1; } joystick->hwdata = hwdata; diff --git a/src/joystick/windows/SDL_windowsjoystick.c b/src/joystick/windows/SDL_windowsjoystick.c index bb95a53ac..3ce542493 100644 --- a/src/joystick/windows/SDL_windowsjoystick.c +++ b/src/joystick/windows/SDL_windowsjoystick.c @@ -670,12 +670,10 @@ static int WINDOWS_JoystickOpen(SDL_Joystick *joystick, int device_index) /* allocate memory for system specific hardware data */ joystick->instance_id = device->nInstanceID; - joystick->hwdata = - (struct joystick_hwdata *)SDL_malloc(sizeof(struct joystick_hwdata)); + joystick->hwdata = (struct joystick_hwdata *)SDL_calloc(1, sizeof(struct joystick_hwdata)); if (!joystick->hwdata) { - return SDL_OutOfMemory(); + return -1; } - SDL_zerop(joystick->hwdata); joystick->hwdata->guid = device->guid; if (device->bXInputDevice) { diff --git a/src/locale/SDL_locale.c b/src/locale/SDL_locale.c index 363d0dd86..aef5d6ffc 100644 --- a/src/locale/SDL_locale.c +++ b/src/locale/SDL_locale.c @@ -48,7 +48,6 @@ static SDL_Locale *build_locales_from_csv_string(char *csv) loc = retval = (SDL_Locale *)SDL_calloc(1, alloclen); if (!retval) { - SDL_OutOfMemory(); return NULL; /* oh well */ } ptr = (char *)(retval + num_locales); diff --git a/src/locale/unix/SDL_syslocale.c b/src/locale/unix/SDL_syslocale.c index bf10e3b19..f420cdf6d 100644 --- a/src/locale/unix/SDL_syslocale.c +++ b/src/locale/unix/SDL_syslocale.c @@ -72,7 +72,7 @@ int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) SDL_assert(buflen > 0); tmp = SDL_small_alloc(char, buflen, &isstack); if (!tmp) { - return SDL_OutOfMemory(); + return -1; } *tmp = '\0'; diff --git a/src/locale/windows/SDL_syslocale.c b/src/locale/windows/SDL_syslocale.c index 977ed0461..e26f129dc 100644 --- a/src/locale/windows/SDL_syslocale.c +++ b/src/locale/windows/SDL_syslocale.c @@ -66,7 +66,7 @@ static int SDL_SYS_GetPreferredLocales_vista(char *buf, size_t buflen) wbuf = SDL_small_alloc(WCHAR, wbuflen, &isstack); if (!wbuf) { - return SDL_OutOfMemory(); + return -1; } if (!pGetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numlangs, wbuf, &wbuflen)) { diff --git a/src/misc/windows/SDL_sysurl.c b/src/misc/windows/SDL_sysurl.c index bb89d55f6..38bf896f7 100644 --- a/src/misc/windows/SDL_sysurl.c +++ b/src/misc/windows/SDL_sysurl.c @@ -47,7 +47,7 @@ int SDL_SYS_OpenURL(const char *url) wurl = WIN_UTF8ToStringW(url); if (!wurl) { WIN_CoUninitialize(); - return SDL_OutOfMemory(); + return -1; } /* Success returns value greater than 32. Less is an error. */ diff --git a/src/misc/winrt/SDL_sysurl.cpp b/src/misc/winrt/SDL_sysurl.cpp index e117a4e14..23bf289d4 100644 --- a/src/misc/winrt/SDL_sysurl.cpp +++ b/src/misc/winrt/SDL_sysurl.cpp @@ -27,7 +27,7 @@ int SDL_SYS_OpenURL(const char *url) { WCHAR *wurl = WIN_UTF8ToStringW(url); if (!wurl) { - return SDL_OutOfMemory(); + return -1; } auto strurl = ref new Platform::String(wurl); SDL_free(wurl); diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 464b8f2e3..f302440ff 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -293,7 +293,6 @@ void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, ptr = SDL_realloc(renderer->vertex_data, newsize); if (!ptr) { - SDL_OutOfMemory(); return NULL; } renderer->vertex_data = ptr; @@ -321,7 +320,6 @@ static SDL_RenderCommand *AllocateRenderCommand(SDL_Renderer *renderer) } else { retval = SDL_calloc(1, sizeof(*retval)); if (!retval) { - SDL_OutOfMemory(); return NULL; } } @@ -1158,7 +1156,6 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert } texture = (SDL_Texture *)SDL_calloc(1, sizeof(*texture)); if (!texture) { - SDL_OutOfMemory(); return NULL; } texture->magic = &SDL_texture_magic; @@ -1566,7 +1563,7 @@ static int SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, if (alloclen > 0) { void *temp_pixels = SDL_malloc(alloclen); if (!temp_pixels) { - return SDL_OutOfMemory(); + return -1; } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, temp_pixels, temp_pitch); @@ -1606,7 +1603,7 @@ static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect, if (alloclen > 0) { void *temp_pixels = SDL_malloc(alloclen); if (!temp_pixels) { - return SDL_OutOfMemory(); + return -1; } SDL_ConvertPixels(rect->w, rect->h, texture->format, pixels, pitch, @@ -1699,7 +1696,7 @@ static int SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect if (alloclen > 0) { void *temp_pixels = SDL_malloc(alloclen); if (!temp_pixels) { - return SDL_OutOfMemory(); + return -1; } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, temp_pixels, temp_pitch); @@ -1749,7 +1746,7 @@ static int SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect, if (alloclen > 0) { void *temp_pixels = SDL_malloc(alloclen); if (!temp_pixels) { - return SDL_OutOfMemory(); + return -1; } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, temp_pixels, temp_pitch); @@ -2694,7 +2691,7 @@ static int RenderPointsWithRects(SDL_Renderer *renderer, const SDL_FPoint *fpoin frects = SDL_small_alloc(SDL_FRect, count, &isstack); if (!frects) { - return SDL_OutOfMemory(); + return -1; } for (i = 0; i < count; ++i) { @@ -2814,7 +2811,7 @@ static int RenderLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x2, i points = SDL_small_alloc(SDL_FPoint, numpixels, &isstack); if (!points) { - return SDL_OutOfMemory(); + return -1; } for (i = 0; i < numpixels; ++i) { points[i].x = (float)x; @@ -2857,7 +2854,7 @@ static int RenderLinesWithRectsF(SDL_Renderer *renderer, frects = SDL_small_alloc(SDL_FRect, count - 1, &isstack); if (!frects) { - return SDL_OutOfMemory(); + return -1; } for (i = 0; i < count - 1; ++i) { @@ -3160,7 +3157,7 @@ int SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int coun frects = SDL_small_alloc(SDL_FRect, count, &isstack); if (!frects) { - return SDL_OutOfMemory(); + return -1; } for (i = 0; i < count; ++i) { frects[i].x = rects[i].x * renderer->view->scale.x; diff --git a/src/render/SDL_yuv_sw.c b/src/render/SDL_yuv_sw.c index 9c123dd04..9a4cc3ac2 100644 --- a/src/render/SDL_yuv_sw.c +++ b/src/render/SDL_yuv_sw.c @@ -47,7 +47,6 @@ SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(Uint32 format, int w, int h) swdata = (SDL_SW_YUVTexture *)SDL_calloc(1, sizeof(*swdata)); if (!swdata) { - SDL_OutOfMemory(); return NULL; } @@ -59,13 +58,11 @@ SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(Uint32 format, int w, int h) size_t dst_size; if (SDL_CalculateYUVSize(format, w, h, &dst_size, NULL) < 0) { SDL_SW_DestroyYUVTexture(swdata); - SDL_OutOfMemory(); return NULL; } swdata->pixels = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), dst_size); if (!swdata->pixels) { SDL_SW_DestroyYUVTexture(swdata); - SDL_OutOfMemory(); return NULL; } } diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index 73a8a7150..744055bcb 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -525,7 +525,7 @@ static int D3D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P texturedata = (D3D_TextureData *)SDL_calloc(1, sizeof(*texturedata)); if (!texturedata) { - return SDL_OutOfMemory(); + return -1; } texturedata->scaleMode = (texture->scaleMode == SDL_SCALEMODE_NEAREST) ? D3DTEXF_POINT : D3DTEXF_LINEAR; @@ -661,7 +661,7 @@ static int D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, texturedata->pitch = texture->w; texturedata->pixels = (Uint8 *)SDL_malloc((texture->h * texturedata->pitch * 3) / 2); if (!texturedata->pixels) { - return SDL_OutOfMemory(); + return -1; } } *pixels = @@ -1562,7 +1562,6 @@ SDL_Renderer *D3D_CreateRenderer(SDL_Window *window, SDL_PropertiesID create_pro renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer)); if (!renderer) { - SDL_OutOfMemory(); return NULL; } renderer->magic = &SDL_renderer_magic; @@ -1570,7 +1569,6 @@ SDL_Renderer *D3D_CreateRenderer(SDL_Window *window, SDL_PropertiesID create_pro data = (D3D_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { SDL_free(renderer); - SDL_OutOfMemory(); return NULL; } diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c index 4119275e6..9dfeb928b 100644 --- a/src/render/direct3d11/SDL_render_d3d11.c +++ b/src/render/direct3d11/SDL_render_d3d11.c @@ -399,7 +399,6 @@ static ID3D11BlendState *D3D11_CreateBlendState(SDL_Renderer *renderer, SDL_Blen blendModes = (D3D11_BlendMode *)SDL_realloc(data->blendModes, (data->blendModesCount + 1) * sizeof(*blendModes)); if (!blendModes) { SAFE_RELEASE(blendState); - SDL_OutOfMemory(); return NULL; } blendModes[data->blendModesCount].blendMode = blendMode; @@ -1095,7 +1094,6 @@ static int D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL textureData = (D3D11_TextureData *)SDL_calloc(1, sizeof(*textureData)); if (!textureData) { - SDL_OutOfMemory(); return -1; } textureData->scaleMode = (texture->scaleMode == SDL_SCALEMODE_NEAREST) ? D3D11_FILTER_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_MIP_LINEAR; @@ -1554,7 +1552,7 @@ static int D3D11_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, textureData->pitch = texture->w; textureData->pixels = (Uint8 *)SDL_malloc((texture->h * textureData->pitch * 3) / 2); if (!textureData->pixels) { - return SDL_OutOfMemory(); + return -1; } } textureData->locked_rect = *rect; @@ -2436,7 +2434,6 @@ SDL_Renderer *D3D11_CreateRenderer(SDL_Window *window, SDL_PropertiesID create_p renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer)); if (!renderer) { - SDL_OutOfMemory(); return NULL; } renderer->magic = &SDL_renderer_magic; @@ -2444,7 +2441,6 @@ SDL_Renderer *D3D11_CreateRenderer(SDL_Window *window, SDL_PropertiesID create_p data = (D3D11_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { SDL_free(renderer); - SDL_OutOfMemory(); return NULL; } diff --git a/src/render/direct3d12/SDL_render_d3d12.c b/src/render/direct3d12/SDL_render_d3d12.c index 195371406..91fdffbde 100644 --- a/src/render/direct3d12/SDL_render_d3d12.c +++ b/src/render/direct3d12/SDL_render_d3d12.c @@ -644,7 +644,6 @@ static D3D12_PipelineState *D3D12_CreatePipelineState(SDL_Renderer *renderer, pipelineStates = (D3D12_PipelineState *)SDL_realloc(data->pipelineStates, (data->pipelineStateCount + 1) * sizeof(*pipelineStates)); if (!pipelineStates) { SAFE_RELEASE(pipelineState); - SDL_OutOfMemory(); return NULL; } @@ -1460,7 +1459,6 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL textureData = (D3D12_TextureData *)SDL_calloc(1, sizeof(*textureData)); if (!textureData) { - SDL_OutOfMemory(); return -1; } textureData->scaleMode = (texture->scaleMode == SDL_SCALEMODE_NEAREST) ? D3D12_FILTER_MIN_MAG_MIP_POINT : D3D12_FILTER_MIN_MAG_MIP_LINEAR; @@ -1910,7 +1908,7 @@ static int D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, textureData->pitch = texture->w; textureData->pixels = (Uint8 *)SDL_malloc((texture->h * textureData->pitch * 3) / 2); if (!textureData->pixels) { - return SDL_OutOfMemory(); + return -1; } } textureData->lockedRect = *rect; @@ -2987,7 +2985,6 @@ SDL_Renderer *D3D12_CreateRenderer(SDL_Window *window, SDL_PropertiesID create_p renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer)); if (!renderer) { - SDL_OutOfMemory(); return NULL; } renderer->magic = &SDL_renderer_magic; @@ -2995,7 +2992,6 @@ SDL_Renderer *D3D12_CreateRenderer(SDL_Window *window, SDL_PropertiesID create_p data = (D3D12_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { SDL_free(renderer); - SDL_OutOfMemory(); return NULL; } diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m index 983e07939..4686fbd88 100644 --- a/src/render/metal/SDL_render_metal.m +++ b/src/render/metal/SDL_render_metal.m @@ -339,7 +339,6 @@ static id MakePipelineState(METAL_RenderData *data, META return (__bridge id)pipeline.pipe; } else { CFBridgingRelease(pipeline.pipe); - SDL_OutOfMemory(); return NULL; } } @@ -401,7 +400,6 @@ static METAL_ShaderPipelines *ChooseShaderPipelines(METAL_RenderData *data, MTLP allpipelines = SDL_realloc(allpipelines, (count + 1) * sizeof(METAL_ShaderPipelines)); if (allpipelines == NULL) { - SDL_OutOfMemory(); return NULL; } @@ -1507,7 +1505,7 @@ static int METAL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect, temp_pitch = rect->w * 4UL; temp_pixels = SDL_malloc(temp_pitch * rect->h); if (!temp_pixels) { - return SDL_OutOfMemory(); + return -1; } [mtltexture getBytes:temp_pixels bytesPerRow:temp_pitch fromRegion:mtlregion mipmapLevel:0]; @@ -1747,7 +1745,6 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window *window, SDL_PropertiesID c renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer)); if (!renderer) { - SDL_OutOfMemory(); return NULL; } diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index 8a102f649..96ca76bd6 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -468,7 +468,7 @@ static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr data = (GL_TextureData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return SDL_OutOfMemory(); + return -1; } if (texture->access == SDL_TEXTUREACCESS_STREAMING) { @@ -488,7 +488,7 @@ static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr data->pixels = SDL_calloc(1, size); if (!data->pixels) { SDL_free(data); - return SDL_OutOfMemory(); + return -1; } } @@ -1483,7 +1483,7 @@ static int GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect, temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); temp_pixels = SDL_malloc((size_t)rect->h * temp_pitch); if (!temp_pixels) { - return SDL_OutOfMemory(); + return -1; } SDL_GetCurrentRenderOutputSize(renderer, &w, &h); @@ -1794,14 +1794,12 @@ static SDL_Renderer *GL_CreateRenderer(SDL_Window *window, SDL_PropertiesID crea renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer)); if (!renderer) { - SDL_OutOfMemory(); goto error; } data = (GL_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { SDL_free(renderer); - SDL_OutOfMemory(); goto error; } diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 9ff464c59..1ea3afde8 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -421,7 +421,6 @@ static GLES2_ProgramCacheEntry *GLES2_CacheProgram(GLES2_RenderData *data, GLuin /* Create a program cache entry */ entry = (GLES2_ProgramCacheEntry *)SDL_calloc(1, sizeof(GLES2_ProgramCacheEntry)); if (!entry) { - SDL_OutOfMemory(); return NULL; } entry->vertex_shader = vertex; @@ -1466,7 +1465,7 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL /* Allocate a texture struct */ data = (GLES2_TextureData *)SDL_calloc(1, sizeof(GLES2_TextureData)); if (!data) { - return SDL_OutOfMemory(); + return -1; } data->texture = 0; #ifdef GL_TEXTURE_EXTERNAL_OES @@ -1501,7 +1500,7 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL data->pixel_data = SDL_calloc(1, size); if (!data->pixel_data) { SDL_free(data); - return SDL_OutOfMemory(); + return -1; } } @@ -1623,7 +1622,7 @@ static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoff if ((size_t)pitch != src_pitch) { blob = (Uint8 *)SDL_malloc(src_pitch * height); if (!blob) { - return SDL_OutOfMemory(); + return -1; } src = blob; for (y = 0; y < height; ++y) { @@ -1946,7 +1945,7 @@ static int GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect, temp_pixels = SDL_malloc(buflen); if (!temp_pixels) { - return SDL_OutOfMemory(); + return -1; } SDL_GetCurrentRenderOutputSize(renderer, &w, &h); @@ -2109,14 +2108,12 @@ static SDL_Renderer *GLES2_CreateRenderer(SDL_Window *window, SDL_PropertiesID c /* Create the renderer struct */ renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer)); if (!renderer) { - SDL_OutOfMemory(); goto error; } data = (GLES2_RenderData *)SDL_calloc(1, sizeof(GLES2_RenderData)); if (!data) { SDL_free(renderer); - SDL_OutOfMemory(); goto error; } renderer->info = GLES2_RenderDriver.info; diff --git a/src/render/ps2/SDL_render_ps2.c b/src/render/ps2/SDL_render_ps2.c index d21c005b4..b715a8586 100644 --- a/src/render/ps2/SDL_render_ps2.c +++ b/src/render/ps2/SDL_render_ps2.c @@ -111,7 +111,7 @@ static int PS2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P GSTEXTURE *ps2_tex = (GSTEXTURE *)SDL_calloc(1, sizeof(GSTEXTURE)); if (!ps2_tex) { - return SDL_OutOfMemory(); + return -1; } ps2_tex->Width = texture->w; @@ -121,7 +121,7 @@ static int PS2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P if (!ps2_tex->Mem) { SDL_free(ps2_tex); - return SDL_OutOfMemory(); + return -1; } texture->driverdata = ps2_tex; @@ -595,14 +595,12 @@ static SDL_Renderer *PS2_CreateRenderer(SDL_Window *window, SDL_PropertiesID cre renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer)); if (!renderer) { - SDL_OutOfMemory(); return NULL; } data = (PS2_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { PS2_DestroyRenderer(renderer); - SDL_OutOfMemory(); return NULL; } diff --git a/src/render/psp/SDL_render_psp.c b/src/render/psp/SDL_render_psp.c index c2f8c3103..df7083720 100644 --- a/src/render/psp/SDL_render_psp.c +++ b/src/render/psp/SDL_render_psp.c @@ -286,7 +286,7 @@ static int TextureSwizzle(PSP_TextureData *psp_texture, void *dst) } if (!data) { - return SDL_OutOfMemory(); + return -1; } for (j = 0; j < height; j++, blockaddress += 16) { @@ -348,7 +348,7 @@ static int TextureUnswizzle(PSP_TextureData *psp_texture, void *dst) } if (!data) { - return SDL_OutOfMemory(); + return -1; } ydst = (unsigned char *)data; @@ -392,7 +392,7 @@ static int TextureSpillToSram(PSP_RenderData *data, PSP_TextureData *psp_texture // Texture was swizzled in vram, just copy to system memory void *sdata = SDL_malloc(psp_texture->size); if (!sdata) { - return SDL_OutOfMemory(); + return -1; } SDL_memcpy(sdata, psp_texture->data, psp_texture->size); @@ -484,7 +484,7 @@ static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P PSP_TextureData *psp_texture = (PSP_TextureData *)SDL_calloc(1, sizeof(*psp_texture)); if (!psp_texture) { - return SDL_OutOfMemory(); + return -1; } psp_texture->swizzled = SDL_FALSE; @@ -527,7 +527,7 @@ static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P if (!psp_texture->data) { SDL_free(psp_texture); - return SDL_OutOfMemory(); + return -1; } texture->driverdata = psp_texture; @@ -1304,14 +1304,12 @@ SDL_Renderer *PSP_CreateRenderer(SDL_Window *window, SDL_PropertiesID create_pro renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer)); if (!renderer) { - SDL_OutOfMemory(); return NULL; } data = (PSP_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { PSP_DestroyRenderer(renderer); - SDL_OutOfMemory(); return NULL; } diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index 5f70345d9..efa30f312 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -1111,14 +1111,12 @@ SDL_Renderer *SW_CreateRendererForSurface(SDL_Surface *surface) renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer)); if (!renderer) { - SDL_OutOfMemory(); return NULL; } data = (SW_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { SW_DestroyRenderer(renderer); - SDL_OutOfMemory(); return NULL; } data->surface = surface; diff --git a/src/render/vitagxm/SDL_render_vita_gxm.c b/src/render/vitagxm/SDL_render_vita_gxm.c index 43cc0e2d2..ade52281e 100644 --- a/src/render/vitagxm/SDL_render_vita_gxm.c +++ b/src/render/vitagxm/SDL_render_vita_gxm.c @@ -218,14 +218,12 @@ SDL_Renderer *VITA_GXM_CreateRenderer(SDL_Window *window, SDL_PropertiesID creat renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer)); if (!renderer) { - SDL_OutOfMemory(); return NULL; } data = (VITA_GXM_RenderData *)SDL_calloc(1, sizeof(VITA_GXM_RenderData)); if (!data) { SDL_free(renderer); - SDL_OutOfMemory(); return NULL; } @@ -298,7 +296,7 @@ static int VITA_GXM_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, VITA_GXM_TextureData *vita_texture = (VITA_GXM_TextureData *)SDL_calloc(1, sizeof(VITA_GXM_TextureData)); if (!vita_texture) { - return SDL_OutOfMemory(); + return -1; } vita_texture->tex = create_gxm_texture( @@ -1111,7 +1109,7 @@ static int VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rec temp_pixels = SDL_malloc(buflen); if (!temp_pixels) { - return SDL_OutOfMemory(); + return -1; } SDL_GetCurrentRenderOutputSize(renderer, &w, &h); diff --git a/src/sensor/SDL_sensor.c b/src/sensor/SDL_sensor.c index 88cda800c..b706261d2 100644 --- a/src/sensor/SDL_sensor.c +++ b/src/sensor/SDL_sensor.c @@ -208,8 +208,6 @@ SDL_SensorID *SDL_GetSensors(int *count) if (count) { *count = 0; } - - SDL_OutOfMemory(); } } SDL_UnlockSensors(); @@ -330,7 +328,6 @@ SDL_Sensor *SDL_OpenSensor(SDL_SensorID instance_id) /* Create and initialize the sensor */ sensor = (SDL_Sensor *)SDL_calloc(sizeof(*sensor), 1); if (!sensor) { - SDL_OutOfMemory(); SDL_UnlockSensors(); return NULL; } diff --git a/src/sensor/android/SDL_androidsensor.c b/src/sensor/android/SDL_androidsensor.c index db137d5e2..b2154b163 100644 --- a/src/sensor/android/SDL_androidsensor.c +++ b/src/sensor/android/SDL_androidsensor.c @@ -147,7 +147,7 @@ static int SDL_ANDROID_SensorInit(void) if (sensors_count > 0) { SDL_sensors = (SDL_AndroidSensor *)SDL_calloc(sensors_count, sizeof(*SDL_sensors)); if (!SDL_sensors) { - return SDL_OutOfMemory(); + return -1; } for (i = 0; i < sensors_count; ++i) { diff --git a/src/sensor/coremotion/SDL_coremotionsensor.m b/src/sensor/coremotion/SDL_coremotionsensor.m index 87021ca20..7fdc28a5d 100644 --- a/src/sensor/coremotion/SDL_coremotionsensor.m +++ b/src/sensor/coremotion/SDL_coremotionsensor.m @@ -57,7 +57,7 @@ static int SDL_COREMOTION_SensorInit(void) if (sensors_count > 0) { SDL_sensors = (SDL_CoreMotionSensor *)SDL_calloc(sensors_count, sizeof(*SDL_sensors)); if (!SDL_sensors) { - return SDL_OutOfMemory(); + return -1; } i = 0; @@ -118,7 +118,7 @@ static int SDL_COREMOTION_SensorOpen(SDL_Sensor *sensor, int device_index) hwdata = (struct sensor_hwdata *)SDL_calloc(1, sizeof(*hwdata)); if (hwdata == NULL) { - return SDL_OutOfMemory(); + return -1; } sensor->hwdata = hwdata; diff --git a/src/sensor/vita/SDL_vitasensor.c b/src/sensor/vita/SDL_vitasensor.c index 9495a5e2d..04323228c 100644 --- a/src/sensor/vita/SDL_vitasensor.c +++ b/src/sensor/vita/SDL_vitasensor.c @@ -52,7 +52,7 @@ static int SDL_VITA_SensorInit(void) SDL_sensors = (SDL_VitaSensor *)SDL_calloc(SDL_sensors_count, sizeof(*SDL_sensors)); if (!SDL_sensors) { - return SDL_OutOfMemory(); + return -1; } SDL_sensors[0].type = SDL_SENSOR_ACCEL; @@ -119,7 +119,7 @@ static int SDL_VITA_SensorOpen(SDL_Sensor *sensor, int device_index) hwdata = (struct sensor_hwdata *)SDL_calloc(1, sizeof(*hwdata)); if (!hwdata) { - return SDL_OutOfMemory(); + return -1; } sensor->hwdata = hwdata; diff --git a/src/sensor/windows/SDL_windowssensor.c b/src/sensor/windows/SDL_windowssensor.c index a3bad4f51..cbd98875c 100644 --- a/src/sensor/windows/SDL_windowssensor.c +++ b/src/sensor/windows/SDL_windowssensor.c @@ -296,7 +296,7 @@ static int ConnectSensor(ISensor *sensor) SysFreeString(bstr_name); } if (!name) { - return SDL_OutOfMemory(); + return -1; } SDL_LockSensors(); @@ -304,7 +304,7 @@ static int ConnectSensor(ISensor *sensor) if (!new_sensors) { SDL_UnlockSensors(); SDL_free(name); - return SDL_OutOfMemory(); + return -1; } ISensor_AddRef(sensor); diff --git a/src/stdlib/SDL_malloc.c b/src/stdlib/SDL_malloc.c index c9ffd8e77..cfa9036c8 100644 --- a/src/stdlib/SDL_malloc.c +++ b/src/stdlib/SDL_malloc.c @@ -5287,7 +5287,10 @@ void *SDL_malloc(size_t size) mem = s_mem.malloc_func(size); if (mem) { SDL_AtomicIncRef(&s_mem.num_allocations); + } else { + SDL_OutOfMemory(); } + return mem; } @@ -5303,7 +5306,10 @@ void *SDL_calloc(size_t nmemb, size_t size) mem = s_mem.calloc_func(nmemb, size); if (mem) { SDL_AtomicIncRef(&s_mem.num_allocations); + } else { + SDL_OutOfMemory(); } + return mem; } @@ -5318,7 +5324,10 @@ void *SDL_realloc(void *ptr, size_t size) mem = s_mem.realloc_func(ptr, size); if (mem && !ptr) { SDL_AtomicIncRef(&s_mem.num_allocations); + } else if (!mem) { + SDL_OutOfMemory(); } + return mem; } diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index efc7e6bef..966c0c016 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -103,7 +103,6 @@ SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, Uint32 flags) state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state)); if (!state) { - SDL_OutOfMemory(); return NULL; } diff --git a/src/thread/SDL_thread.c b/src/thread/SDL_thread.c index 49f24d47e..84ec9a9ed 100644 --- a/src/thread/SDL_thread.c +++ b/src/thread/SDL_thread.c @@ -60,7 +60,7 @@ int SDL_SetTLS(SDL_TLSID id, const void *value, void(SDLCALL *destructor)(void * newlimit = (id + TLS_ALLOC_CHUNKSIZE); new_storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage) + (newlimit - 1) * sizeof(storage->array[0])); if (!new_storage) { - return SDL_OutOfMemory(); + return -1; } storage = new_storage; storage->limit = newlimit; @@ -186,10 +186,7 @@ int SDL_Generic_SetTLSData(SDL_TLSData *data) } SDL_UnlockMutex(SDL_generic_TLS_mutex); - if (!entry) { - return SDL_OutOfMemory(); - } - return 0; + return entry ? 0 : -1; } /* Non-thread-safe global error variable */ @@ -331,7 +328,6 @@ SDL_Thread *SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *), /* Allocate memory for the thread info structure */ thread = (SDL_Thread *)SDL_calloc(1, sizeof(*thread)); if (!thread) { - SDL_OutOfMemory(); return NULL; } thread->status = -1; @@ -341,7 +337,6 @@ SDL_Thread *SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *), if (name) { thread->name = SDL_strdup(name); if (!thread->name) { - SDL_OutOfMemory(); SDL_free(thread); return NULL; } diff --git a/src/thread/generic/SDL_syscond.c b/src/thread/generic/SDL_syscond.c index e6b1a5d6b..6a8b06aa8 100644 --- a/src/thread/generic/SDL_syscond.c +++ b/src/thread/generic/SDL_syscond.c @@ -64,8 +64,6 @@ SDL_Condition *SDL_CreateCondition_generic(void) SDL_DestroyCondition_generic((SDL_Condition *)cond); cond = NULL; } - } else { - SDL_OutOfMemory(); } return (SDL_Condition *)cond; } diff --git a/src/thread/generic/SDL_sysmutex.c b/src/thread/generic/SDL_sysmutex.c index 95f4cecd1..1f21ca506 100644 --- a/src/thread/generic/SDL_sysmutex.c +++ b/src/thread/generic/SDL_sysmutex.c @@ -45,8 +45,6 @@ SDL_Mutex *SDL_CreateMutex(void) SDL_free(mutex); mutex = NULL; } - } else { - SDL_OutOfMemory(); } #endif // !SDL_THREADS_DISABLED diff --git a/src/thread/generic/SDL_sysrwlock.c b/src/thread/generic/SDL_sysrwlock.c index a38b81d6a..73c15e961 100644 --- a/src/thread/generic/SDL_sysrwlock.c +++ b/src/thread/generic/SDL_sysrwlock.c @@ -59,7 +59,6 @@ SDL_RWLock *SDL_CreateRWLock_generic(void) SDL_RWLock *rwlock = (SDL_RWLock *) SDL_calloc(1, sizeof (*rwlock)); if (!rwlock) { - SDL_OutOfMemory(); return NULL; } diff --git a/src/thread/generic/SDL_syssem.c b/src/thread/generic/SDL_syssem.c index bf945695f..e2e0f9ca9 100644 --- a/src/thread/generic/SDL_syssem.c +++ b/src/thread/generic/SDL_syssem.c @@ -67,7 +67,6 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value) sem = (SDL_Semaphore *)SDL_malloc(sizeof(*sem)); if (!sem) { - SDL_OutOfMemory(); return NULL; } sem->count = initial_value; diff --git a/src/thread/n3ds/SDL_syscond.c b/src/thread/n3ds/SDL_syscond.c index 5595010fb..aae480b23 100644 --- a/src/thread/n3ds/SDL_syscond.c +++ b/src/thread/n3ds/SDL_syscond.c @@ -37,8 +37,6 @@ SDL_Condition *SDL_CreateCondition(void) SDL_Condition *cond = (SDL_Condition *)SDL_malloc(sizeof(SDL_Condition)); if (cond) { CondVar_Init(&cond->cond_variable); - } else { - SDL_OutOfMemory(); } return cond; } diff --git a/src/thread/n3ds/SDL_sysmutex.c b/src/thread/n3ds/SDL_sysmutex.c index 57d189db5..614555178 100644 --- a/src/thread/n3ds/SDL_sysmutex.c +++ b/src/thread/n3ds/SDL_sysmutex.c @@ -31,8 +31,6 @@ SDL_Mutex *SDL_CreateMutex(void) SDL_Mutex *mutex = (SDL_Mutex *)SDL_malloc(sizeof(*mutex)); if (mutex) { RecursiveLock_Init(&mutex->lock); - } else { - SDL_OutOfMemory(); } return mutex; } diff --git a/src/thread/n3ds/SDL_syssem.c b/src/thread/n3ds/SDL_syssem.c index f41d69c34..31bca0dd2 100644 --- a/src/thread/n3ds/SDL_syssem.c +++ b/src/thread/n3ds/SDL_syssem.c @@ -44,7 +44,6 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value) sem = (SDL_Semaphore *)SDL_malloc(sizeof(*sem)); if (!sem) { - SDL_OutOfMemory(); return NULL; } diff --git a/src/thread/ps2/SDL_syssem.c b/src/thread/ps2/SDL_syssem.c index 04e0b2d83..ceb191181 100644 --- a/src/thread/ps2/SDL_syssem.c +++ b/src/thread/ps2/SDL_syssem.c @@ -59,8 +59,6 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value) SDL_free(sem); sem = NULL; } - } else { - SDL_OutOfMemory(); } return sem; diff --git a/src/thread/psp/SDL_syscond.c b/src/thread/psp/SDL_syscond.c index 0dc6f177d..bfe4f42ba 100644 --- a/src/thread/psp/SDL_syscond.c +++ b/src/thread/psp/SDL_syscond.c @@ -52,8 +52,6 @@ SDL_Condition *SDL_CreateCondition(void) SDL_DestroyCondition(cond); cond = NULL; } - } else { - SDL_OutOfMemory(); } return cond; } diff --git a/src/thread/psp/SDL_sysmutex.c b/src/thread/psp/SDL_sysmutex.c index 82e63e6fe..7fb94ee75 100644 --- a/src/thread/psp/SDL_sysmutex.c +++ b/src/thread/psp/SDL_sysmutex.c @@ -52,8 +52,6 @@ SDL_Mutex *SDL_CreateMutex(void) mutex = NULL; SDL_SetError("Error trying to create mutex: %lx", res); } - } else { - SDL_OutOfMemory(); } return mutex; } diff --git a/src/thread/psp/SDL_syssem.c b/src/thread/psp/SDL_syssem.c index c6b1a3c57..098a15bb3 100644 --- a/src/thread/psp/SDL_syssem.c +++ b/src/thread/psp/SDL_syssem.c @@ -49,8 +49,6 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value) SDL_free(sem); sem = NULL; } - } else { - SDL_OutOfMemory(); } return sem; diff --git a/src/thread/pthread/SDL_sysmutex.c b/src/thread/pthread/SDL_sysmutex.c index 30f796cd7..9ffbd53c5 100644 --- a/src/thread/pthread/SDL_sysmutex.c +++ b/src/thread/pthread/SDL_sysmutex.c @@ -46,8 +46,6 @@ SDL_Mutex *SDL_CreateMutex(void) SDL_free(mutex); mutex = NULL; } - } else { - SDL_OutOfMemory(); } return mutex; } diff --git a/src/thread/pthread/SDL_sysrwlock.c b/src/thread/pthread/SDL_sysrwlock.c index 485264e85..6d70ac8ea 100644 --- a/src/thread/pthread/SDL_sysrwlock.c +++ b/src/thread/pthread/SDL_sysrwlock.c @@ -41,8 +41,6 @@ SDL_RWLock *SDL_CreateRWLock(void) SDL_free(rwlock); rwlock = NULL; } - } else { - SDL_OutOfMemory(); } return rwlock; } diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c index d2ecb57d9..0593e4b2a 100644 --- a/src/thread/pthread/SDL_syssem.c +++ b/src/thread/pthread/SDL_syssem.c @@ -48,8 +48,6 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value) SDL_free(sem); sem = NULL; } - } else { - SDL_OutOfMemory(); } return sem; } diff --git a/src/thread/vita/SDL_syscond.c b/src/thread/vita/SDL_syscond.c index 2218f755e..fc8e1c9e3 100644 --- a/src/thread/vita/SDL_syscond.c +++ b/src/thread/vita/SDL_syscond.c @@ -52,8 +52,6 @@ SDL_Condition *SDL_CreateCondition(void) SDL_DestroyCondition(cond); cond = NULL; } - } else { - SDL_OutOfMemory(); } return cond; } diff --git a/src/thread/vita/SDL_sysmutex.c b/src/thread/vita/SDL_sysmutex.c index e63e77fa5..38f31ab05 100644 --- a/src/thread/vita/SDL_sysmutex.c +++ b/src/thread/vita/SDL_sysmutex.c @@ -48,8 +48,6 @@ SDL_Mutex *SDL_CreateMutex(void) mutex = NULL; SDL_SetError("Error trying to create mutex: %x", res); } - } else { - SDL_OutOfMemory(); } return mutex; } diff --git a/src/thread/vita/SDL_syssem.c b/src/thread/vita/SDL_syssem.c index f43cbaba5..ca8636c35 100644 --- a/src/thread/vita/SDL_syssem.c +++ b/src/thread/vita/SDL_syssem.c @@ -50,8 +50,6 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value) SDL_free(sem); sem = NULL; } - } else { - SDL_OutOfMemory(); } return sem; diff --git a/src/thread/windows/SDL_syscond_cv.c b/src/thread/windows/SDL_syscond_cv.c index 91a5e23bd..fdc806411 100644 --- a/src/thread/windows/SDL_syscond_cv.c +++ b/src/thread/windows/SDL_syscond_cv.c @@ -80,23 +80,14 @@ typedef struct SDL_cond_cv static SDL_Condition *SDL_CreateCondition_cv(void) { - SDL_cond_cv *cond; - /* Relies on CONDITION_VARIABLE_INIT == 0. */ - cond = (SDL_cond_cv *)SDL_calloc(1, sizeof(*cond)); - if (!cond) { - SDL_OutOfMemory(); - } - - return (SDL_Condition *)cond; + return (SDL_Condition *)SDL_calloc(1, sizeof(SDL_cond_cv)); } static void SDL_DestroyCondition_cv(SDL_Condition *cond) { - if (cond) { - /* There are no kernel allocated resources */ - SDL_free(cond); - } + /* There are no kernel allocated resources */ + SDL_free(cond); } static int SDL_SignalCondition_cv(SDL_Condition *_cond) diff --git a/src/thread/windows/SDL_sysmutex.c b/src/thread/windows/SDL_sysmutex.c index 1d62e7e8d..aef7e9312 100644 --- a/src/thread/windows/SDL_sysmutex.c +++ b/src/thread/windows/SDL_sysmutex.c @@ -58,15 +58,10 @@ static pfnTryAcquireSRWLockExclusive pTryAcquireSRWLockExclusive = NULL; static SDL_Mutex *SDL_CreateMutex_srw(void) { - SDL_mutex_srw *mutex; - - mutex = (SDL_mutex_srw *)SDL_calloc(1, sizeof(*mutex)); - if (!mutex) { - SDL_OutOfMemory(); + SDL_mutex_srw *mutex = (SDL_mutex_srw *)SDL_calloc(1, sizeof(*mutex)); + if (mutex) { + pInitializeSRWLock(&mutex->srw); } - - pInitializeSRWLock(&mutex->srw); - return (SDL_Mutex *)mutex; } @@ -153,8 +148,6 @@ static SDL_Mutex *SDL_CreateMutex_cs(void) #else InitializeCriticalSectionAndSpinCount(&mutex->cs, 2000); #endif - } else { - SDL_OutOfMemory(); } return (SDL_Mutex *)mutex; } diff --git a/src/thread/windows/SDL_sysrwlock_srw.c b/src/thread/windows/SDL_sysrwlock_srw.c index 5b5953a38..864743fdb 100644 --- a/src/thread/windows/SDL_sysrwlock_srw.c +++ b/src/thread/windows/SDL_sysrwlock_srw.c @@ -88,10 +88,9 @@ typedef struct SDL_rwlock_srw static SDL_RWLock *SDL_CreateRWLock_srw(void) { SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *)SDL_calloc(1, sizeof(*rwlock)); - if (!rwlock) { - SDL_OutOfMemory(); + if (rwlock) { + pInitializeSRWLock(&rwlock->srw); } - pInitializeSRWLock(&rwlock->srw); return (SDL_RWLock *)rwlock; } diff --git a/src/thread/windows/SDL_syssem.c b/src/thread/windows/SDL_syssem.c index 493dd3178..acb0950bc 100644 --- a/src/thread/windows/SDL_syssem.c +++ b/src/thread/windows/SDL_syssem.c @@ -85,17 +85,13 @@ static SDL_Semaphore *SDL_CreateSemaphore_atom(Uint32 initial_value) sem = (SDL_sem_atom *)SDL_malloc(sizeof(*sem)); if (sem) { sem->count = initial_value; - } else { - SDL_OutOfMemory(); } return (SDL_Semaphore *)sem; } static void SDL_DestroySemaphore_atom(SDL_Semaphore *sem) { - if (sem) { - SDL_free(sem); - } + SDL_free(sem); } static int SDL_WaitSemaphoreTimeoutNS_atom(SDL_Semaphore *_sem, Sint64 timeoutNS) @@ -226,6 +222,7 @@ static SDL_Semaphore *SDL_CreateSemaphore_kern(Uint32 initial_value) sem = (SDL_sem_kern *)SDL_malloc(sizeof(*sem)); if (sem) { /* Create the semaphore, with max value 32K */ +// !!! FIXME: CreateSemaphoreEx is available in Vista and later, so if XP support is dropped, we can lose this #ifdef. #ifdef __WINRT__ sem->id = CreateSemaphoreEx(NULL, initial_value, 32 * 1024, NULL, 0, SEMAPHORE_ALL_ACCESS); #else @@ -237,8 +234,6 @@ static SDL_Semaphore *SDL_CreateSemaphore_kern(Uint32 initial_value) SDL_free(sem); sem = NULL; } - } else { - SDL_OutOfMemory(); } return (SDL_Semaphore *)sem; } diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c index a5ca67579..4b72503d6 100644 --- a/src/timer/SDL_timer.c +++ b/src/timer/SDL_timer.c @@ -297,7 +297,6 @@ SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *para } else { timer = (SDL_Timer *)SDL_malloc(sizeof(*timer)); if (!timer) { - SDL_OutOfMemory(); return 0; } } @@ -311,7 +310,6 @@ SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *para entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry)); if (!entry) { SDL_free(timer); - SDL_OutOfMemory(); return 0; } entry->timer = timer; @@ -423,7 +421,6 @@ SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *para entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry)); if (!entry) { - SDL_OutOfMemory(); return 0; } entry->timerID = ++data->nextID; diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c index a9e82465c..2bfd6edb4 100644 --- a/src/video/SDL_RLEaccel.c +++ b/src/video/SDL_RLEaccel.c @@ -1081,7 +1081,7 @@ static int RLEAlphaSurface(SDL_Surface *surface) maxsize += sizeof(RLEDestFormat); rlebuf = (Uint8 *)SDL_malloc(maxsize); if (!rlebuf) { - return SDL_OutOfMemory(); + return -1; } { /* save the destination format so we can undo the encoding later */ @@ -1300,7 +1300,7 @@ static int RLEColorkeySurface(SDL_Surface *surface) rlebuf = (Uint8 *)SDL_malloc(maxsize); if (!rlebuf) { - return SDL_OutOfMemory(); + return -1; } /* Set up the conversion */ diff --git a/src/video/SDL_clipboard.c b/src/video/SDL_clipboard.c index df116314b..e6266724e 100644 --- a/src/video/SDL_clipboard.c +++ b/src/video/SDL_clipboard.c @@ -97,7 +97,7 @@ int SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanu } if (num_allocated < num_mime_types) { SDL_ClearClipboardData(); - return SDL_OutOfMemory(); + return -1; } _this->num_clipboard_mime_types = num_mime_types; } @@ -156,8 +156,6 @@ void *SDL_GetInternalClipboardData(SDL_VideoDevice *_this, const char *mime_type if (data) { SDL_memcpy(data, provided_data, *size); SDL_memset((Uint8 *)data + *size, 0, sizeof(Uint32)); - } else { - SDL_OutOfMemory(); } } } diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index a2d72114b..60c66f37d 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -476,7 +476,7 @@ int SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *egl_path) _this->egl_data = (struct SDL_EGL_VideoData *)SDL_calloc(1, sizeof(SDL_EGL_VideoData)); if (!_this->egl_data) { - return SDL_OutOfMemory(); + return -1; } if (SDL_EGL_LoadLibraryInternal(_this, egl_path) < 0) { diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index aaeb1d9f2..d7be3e136 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -565,7 +565,6 @@ SDL_PixelFormat *SDL_CreatePixelFormat(Uint32 pixel_format) format = SDL_malloc(sizeof(*format)); if (!format) { SDL_AtomicUnlock(&formats_lock); - SDL_OutOfMemory(); return NULL; } if (SDL_InitFormat(format, pixel_format) < 0) { @@ -705,14 +704,12 @@ SDL_Palette *SDL_CreatePalette(int ncolors) palette = (SDL_Palette *)SDL_malloc(sizeof(*palette)); if (!palette) { - SDL_OutOfMemory(); return NULL; } palette->colors = (SDL_Color *)SDL_malloc(ncolors * sizeof(*palette->colors)); if (!palette->colors) { SDL_free(palette); - SDL_OutOfMemory(); return NULL; } palette->ncolors = ncolors; @@ -989,7 +986,6 @@ static Uint8 *Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical) } map = (Uint8 *)SDL_calloc(256, sizeof(Uint8)); if (!map) { - SDL_OutOfMemory(); return NULL; } for (i = 0; i < src->ncolors; ++i) { @@ -1012,7 +1008,6 @@ static Uint8 *Map1toN(SDL_PixelFormat *src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel); map = (Uint8 *)SDL_calloc(256, bpp); if (!map) { - SDL_OutOfMemory(); return NULL; } @@ -1048,7 +1043,6 @@ SDL_BlitMap *SDL_AllocBlitMap(void) /* Allocate the empty map */ map = (SDL_BlitMap *)SDL_calloc(1, sizeof(*map)); if (!map) { - SDL_OutOfMemory(); return NULL; } map->info.r = 0xFF; diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index bc71c5413..b59df0c51 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -136,14 +136,12 @@ SDL_Surface *SDL_CreateSurface(int width, int height, Uint32 format) if (SDL_CalculateSize(format, width, height, &size, &pitch, SDL_FALSE /* not minimal pitch */) < 0) { /* Overflow... */ - SDL_OutOfMemory(); return NULL; } /* Allocate the surface */ surface = (SDL_Surface *)SDL_calloc(1, sizeof(*surface)); if (!surface) { - SDL_OutOfMemory(); return NULL; } @@ -182,7 +180,6 @@ SDL_Surface *SDL_CreateSurface(int width, int height, Uint32 format) surface->pixels = SDL_aligned_alloc(SDL_SIMDGetAlignment(), size); if (!surface->pixels) { SDL_DestroySurface(surface); - SDL_OutOfMemory(); return NULL; } surface->flags |= SDL_SIMD_ALIGNED; @@ -232,7 +229,6 @@ SDL_Surface *SDL_CreateSurfaceFrom(void *pixels, int width, int height, int pitc if (SDL_CalculateSize(format, width, height, NULL, &minimalPitch, SDL_TRUE /* minimal pitch */) < 0) { /* Overflow... */ - SDL_OutOfMemory(); return NULL; } diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index ee6972193..3f416f2b7 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -277,7 +277,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, U data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data)); if (!data) { SDL_DestroyRenderer(renderer); - return SDL_OutOfMemory(); + return -1; } SDL_SetPropertyWithCleanup(props, SDL_WINDOWTEXTUREDATA, data, SDL_CleanupWindowTextureData, NULL); @@ -324,7 +324,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, U const size_t allocsize = (size_t)h * data->pitch; data->pixels = SDL_malloc((allocsize > 0) ? allocsize : 1); if (!data->pixels) { - return SDL_OutOfMemory(); + return -1; } } @@ -657,13 +657,11 @@ SDL_DisplayID SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send new_display = (SDL_VideoDisplay *)SDL_malloc(sizeof(*new_display)); if (!new_display) { - SDL_OutOfMemory(); return 0; } displays = (SDL_VideoDisplay **)SDL_realloc(_this->displays, (_this->num_displays + 1) * sizeof(*displays)); if (!displays) { - SDL_OutOfMemory(); SDL_free(new_display); return 0; } @@ -767,8 +765,6 @@ SDL_DisplayID *SDL_GetDisplays(int *count) if (count) { *count = 0; } - - SDL_OutOfMemory(); } return displays; } @@ -1105,8 +1101,6 @@ const SDL_DisplayMode **SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, i if (count) { *count = 0; } - - SDL_OutOfMemory(); } return modes; } @@ -2020,7 +2014,6 @@ SDL_Window *SDL_CreateWindowWithProperties(SDL_PropertiesID props) window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); if (!window) { - SDL_OutOfMemory(); return NULL; } window->magic = &_this->window_magic; diff --git a/src/video/SDL_vulkan_utils.c b/src/video/SDL_vulkan_utils.c index a16908a9d..f31d1009d 100644 --- a/src/video/SDL_vulkan_utils.c +++ b/src/video/SDL_vulkan_utils.c @@ -149,7 +149,6 @@ VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList( } if (!retval) { - SDL_OutOfMemory(); return NULL; } @@ -229,7 +228,6 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, physicalDevices = SDL_malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount); if (!physicalDevices) { - SDL_OutOfMemory(); goto error; } @@ -272,7 +270,6 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, displayProperties = SDL_malloc(sizeof(VkDisplayPropertiesKHR) * displayPropertiesCount); if (!displayProperties) { - SDL_OutOfMemory(); goto error; } @@ -301,7 +298,6 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, displayModeProperties = SDL_malloc(sizeof(VkDisplayModePropertiesKHR) * displayModePropertiesCount); if (!displayModeProperties) { - SDL_OutOfMemory(); goto error; } @@ -348,7 +344,6 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, displayPlaneProperties = SDL_malloc(sizeof(VkDisplayPlanePropertiesKHR) * displayPlanePropertiesCount); if (!displayPlaneProperties) { - SDL_OutOfMemory(); goto error; } @@ -380,7 +375,6 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, planeSupportedDisplays = SDL_malloc(sizeof(VkDisplayKHR) * planeSupportedDisplaysCount); if (!planeSupportedDisplays) { SDL_free(displayPlaneProperties); - SDL_OutOfMemory(); goto error; } diff --git a/src/video/SDL_yuv.c b/src/video/SDL_yuv.c index 6eb248bb6..e8db13381 100644 --- a/src/video/SDL_yuv.c +++ b/src/video/SDL_yuv.c @@ -616,7 +616,7 @@ int SDL_ConvertPixels_YUV_to_RGB(int width, int height, tmp = SDL_malloc((size_t)tmp_pitch * height); if (!tmp) { - return SDL_OutOfMemory(); + return -1; } /* convert src/src_format to tmp/ARGB8888 */ @@ -997,7 +997,7 @@ int SDL_ConvertPixels_RGB_to_YUV(int width, int height, tmp = SDL_malloc((size_t)tmp_pitch * height); if (!tmp) { - return SDL_OutOfMemory(); + return -1; } /* convert src/src_format to tmp/ARGB8888 */ @@ -1086,7 +1086,7 @@ static int SDL_ConvertPixels_SwapUVPlanes(int width, int height, const void *src /* Allocate a temporary row for the swap */ tmp = (Uint8 *)SDL_malloc(UVwidth); if (!tmp) { - return SDL_OutOfMemory(); + return -1; } for (y = 0; y < UVheight; ++y) { SDL_memcpy(tmp, row1, UVwidth); @@ -1144,7 +1144,7 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_PackUVPlanes_to_NV_SSE2(int w /* Need to make a copy of the buffer so we don't clobber it while converting */ tmp = (Uint8 *)SDL_malloc((size_t)2 * UVheight * srcUVPitch); if (tmp == NULL) { - return SDL_OutOfMemory(); + return -1; } SDL_memcpy(tmp, src, (size_t)2 * UVheight * srcUVPitch); src = tmp; @@ -1210,7 +1210,7 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_SplitNV_to_UVPlanes_SSE2(int /* Need to make a copy of the buffer so we don't clobber it while converting */ tmp = (Uint8 *)SDL_malloc((size_t)UVheight * srcUVPitch); if (tmp == NULL) { - return SDL_OutOfMemory(); + return -1; } SDL_memcpy(tmp, src, (size_t)UVheight * srcUVPitch); src = tmp; @@ -1322,7 +1322,7 @@ static int SDL_ConvertPixels_PackUVPlanes_to_NV_std(int width, int height, const /* Need to make a copy of the buffer so we don't clobber it while converting */ tmp = (Uint8 *)SDL_malloc((size_t)2 * UVheight * srcUVPitch); if (!tmp) { - return SDL_OutOfMemory(); + return -1; } SDL_memcpy(tmp, src, (size_t)2 * UVheight * srcUVPitch); src = tmp; @@ -1376,7 +1376,7 @@ static int SDL_ConvertPixels_SplitNV_to_UVPlanes_std(int width, int height, cons /* Need to make a copy of the buffer so we don't clobber it while converting */ tmp = (Uint8 *)SDL_malloc((size_t)UVheight * srcUVPitch); if (!tmp) { - return SDL_OutOfMemory(); + return -1; } SDL_memcpy(tmp, src, (size_t)UVheight * srcUVPitch); src = tmp; diff --git a/src/video/android/SDL_androidmouse.c b/src/video/android/SDL_androidmouse.c index bc97260b1..c3b7b14f2 100644 --- a/src/video/android/SDL_androidmouse.c +++ b/src/video/android/SDL_androidmouse.c @@ -68,10 +68,7 @@ static SDL_Cursor *Android_WrapCursor(int custom_cursor, int system_cursor) } else { SDL_free(cursor); cursor = NULL; - SDL_OutOfMemory(); } - } else { - SDL_OutOfMemory(); } return cursor; diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c index 1d6d0c282..e9b42a64d 100644 --- a/src/video/android/SDL_androidvideo.c +++ b/src/video/android/SDL_androidvideo.c @@ -87,13 +87,11 @@ static SDL_VideoDevice *Android_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return NULL; } data = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); if (!data) { - SDL_OutOfMemory(); SDL_free(device); return NULL; } diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c index 911345d22..c33a5ceef 100644 --- a/src/video/android/SDL_androidwindow.c +++ b/src/video/android/SDL_androidwindow.c @@ -62,7 +62,7 @@ int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert data = (SDL_WindowData *)SDL_calloc(1, sizeof(*data)); if (!data) { - retval = SDL_OutOfMemory(); + retval = -1; goto endfunction; } diff --git a/src/video/cocoa/SDL_cocoaclipboard.m b/src/video/cocoa/SDL_cocoaclipboard.m index a6f85a13b..a02c1f062 100644 --- a/src/video/cocoa/SDL_cocoaclipboard.m +++ b/src/video/cocoa/SDL_cocoaclipboard.m @@ -148,8 +148,6 @@ void *Cocoa_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size if (data) { [itemData getBytes: data length: length]; SDL_memset((Uint8 *)data + length, 0, sizeof(Uint32)); - } else { - SDL_OutOfMemory(); } break; } diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index e570397ee..49f828125 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -393,7 +393,7 @@ int Cocoa_InitMouse(SDL_VideoDevice *_this) SDL_Mouse *mouse = SDL_GetMouse(); SDL_MouseData *driverdata = (SDL_MouseData *)SDL_calloc(1, sizeof(SDL_MouseData)); if (driverdata == NULL) { - return SDL_OutOfMemory(); + return -1; } mouse->driverdata = driverdata; diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index 0d93a5ef0..588d9e8c7 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -68,7 +68,6 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void) data = nil; } if (!data) { - SDL_OutOfMemory(); SDL_free(device); return NULL; } diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 964cfa0e6..debb76fdc 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -2458,7 +2458,6 @@ void *Cocoa_GetWindowICCProfile(SDL_VideoDevice *_this, SDL_Window *window, size retIccProfileData = SDL_malloc([iccProfileData length]); if (!retIccProfileData) { - SDL_OutOfMemory(); return NULL; } diff --git a/src/video/dummy/SDL_nullvideo.c b/src/video/dummy/SDL_nullvideo.c index 6a85ac980..64dad5afd 100644 --- a/src/video/dummy/SDL_nullvideo.c +++ b/src/video/dummy/SDL_nullvideo.c @@ -84,7 +84,6 @@ static SDL_VideoDevice *DUMMY_InternalCreateDevice(const char *enable_hint) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return 0; } device->is_dummy = SDL_TRUE; diff --git a/src/video/emscripten/SDL_emscriptenmouse.c b/src/video/emscripten/SDL_emscriptenmouse.c index 2362d8837..40d1af8af 100644 --- a/src/video/emscripten/SDL_emscriptenmouse.c +++ b/src/video/emscripten/SDL_emscriptenmouse.c @@ -42,14 +42,11 @@ static SDL_Cursor *Emscripten_CreateCursorFromString(const char *cursor_str, SDL_bool is_custom) { - SDL_Cursor *cursor; Emscripten_CursorData *curdata; - - cursor = SDL_calloc(1, sizeof(SDL_Cursor)); + SDL_Cursor *cursor = SDL_calloc(1, sizeof(SDL_Cursor)); if (cursor) { curdata = (Emscripten_CursorData *)SDL_calloc(1, sizeof(*curdata)); if (!curdata) { - SDL_OutOfMemory(); SDL_free(cursor); return NULL; } @@ -57,8 +54,6 @@ static SDL_Cursor *Emscripten_CreateCursorFromString(const char *cursor_str, SDL curdata->system_cursor = cursor_str; curdata->is_custom = is_custom; cursor->driverdata = curdata; - } else { - SDL_OutOfMemory(); } return cursor; diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c index 43e74764c..000dc192d 100644 --- a/src/video/emscripten/SDL_emscriptenvideo.c +++ b/src/video/emscripten/SDL_emscriptenvideo.c @@ -62,7 +62,6 @@ static SDL_VideoDevice *Emscripten_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return 0; } @@ -181,7 +180,7 @@ static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, S /* Allocate window internal data */ wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!wdata) { - return SDL_OutOfMemory(); + return -1; } selector = SDL_GetHint(SDL_HINT_EMSCRIPTEN_CANVAS_SELECTOR); diff --git a/src/video/gdk/SDL_gdktextinput.cpp b/src/video/gdk/SDL_gdktextinput.cpp index b07319881..c4bdc83ea 100644 --- a/src/video/gdk/SDL_gdktextinput.cpp +++ b/src/video/gdk/SDL_gdktextinput.cpp @@ -88,10 +88,7 @@ static void SDLCALL GDK_InternalHintCallback( *(char **)userdata = NULL; } else { char *newString = SDL_strdup(newValue); - if (!newString) { - /* couldn't strdup, oh well */ - SDL_OutOfMemory(); - } else { + if (newString) { /* free previous value and write the new one */ SDL_free(*(char **)userdata); *(char **)userdata = newString; @@ -128,9 +125,7 @@ static void CALLBACK GDK_InternalTextEntryCallback(XAsyncBlock *asyncBlock) } else if (resultSize > 0) { /* +1 to be super sure that the buffer will be null terminated */ resultBuffer = (char *)SDL_calloc(sizeof(*resultBuffer), 1 + (size_t)resultSize); - if (!resultBuffer) { - SDL_OutOfMemory(); - } else { + if (resultBuffer) { /* still pass the original size that we got from ResultSize */ if (FAILED(hR = XGameUiShowTextEntryResult( asyncBlock, @@ -263,7 +258,6 @@ void GDK_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window) g_TextBlock = (XAsyncBlock *)SDL_calloc(1, sizeof(*g_TextBlock)); if (!g_TextBlock) { - SDL_OutOfMemory(); return; } diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc index 6e881a6e9..470242d99 100644 --- a/src/video/haiku/SDL_bvideo.cc +++ b/src/video/haiku/SDL_bvideo.cc @@ -165,8 +165,6 @@ static SDL_Cursor * HAIKU_CreateSystemCursor(SDL_SystemCursor id) cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor)); if (cursor) { cursor->driverdata = (void *)new BCursor(cursorId); - } else { - SDL_OutOfMemory(); } return cursor; diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.c b/src/video/kmsdrm/SDL_kmsdrmmouse.c index 1e092726a..513f5f533 100644 --- a/src/video/kmsdrm/SDL_kmsdrmmouse.c +++ b/src/video/kmsdrm/SDL_kmsdrmmouse.c @@ -159,7 +159,7 @@ static int KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor) ready_buffer = (uint8_t *)SDL_calloc(1, bufsize); if (!ready_buffer) { - ret = SDL_OutOfMemory(); + ret = -1; goto cleanup; } @@ -237,12 +237,10 @@ static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface *surface, int hot_x, int hot_ cursor = (SDL_Cursor *)SDL_calloc(1, sizeof(*cursor)); if (!cursor) { - SDL_OutOfMemory(); goto cleanup; } curdata = (KMSDRM_CursorData *)SDL_calloc(1, sizeof(*curdata)); if (!curdata) { - SDL_OutOfMemory(); goto cleanup; } @@ -260,7 +258,6 @@ static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface *surface, int hot_x, int hot_ curdata->buffer = (uint32_t *)SDL_malloc(curdata->buffer_size); if (!curdata->buffer) { - SDL_OutOfMemory(); goto cleanup; } diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index ac28f6e16..4ec049d67 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -261,13 +261,11 @@ static SDL_VideoDevice *KMSDRM_CreateDevice(void) device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return NULL; } viddata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); if (!viddata) { - SDL_OutOfMemory(); goto cleanup; } viddata->devindex = devindex; @@ -364,7 +362,6 @@ KMSDRM_FBInfo *KMSDRM_FBFromBO(SDL_VideoDevice *_this, struct gbm_bo *bo) fb_info = (KMSDRM_FBInfo *)SDL_calloc(1, sizeof(KMSDRM_FBInfo)); if (!fb_info) { - SDL_OutOfMemory(); return NULL; } @@ -689,7 +686,7 @@ static void KMSDRM_AddDisplay(SDL_VideoDevice *_this, drmModeConnector *connecto /* Reserve memory for the new display's driverdata. */ dispdata = (SDL_DisplayData *)SDL_calloc(1, sizeof(SDL_DisplayData)); if (!dispdata) { - ret = SDL_OutOfMemory(); + ret = -1; goto cleanup; } @@ -852,7 +849,7 @@ static void KMSDRM_AddDisplay(SDL_VideoDevice *_this, drmModeConnector *connecto modedata = SDL_calloc(1, sizeof(SDL_DisplayModeData)); if (!modedata) { - ret = SDL_OutOfMemory(); + ret = -1; goto cleanup; } @@ -1460,7 +1457,7 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti /* Allocate window internal data */ windata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!windata) { - return SDL_OutOfMemory(); + return -1; } /* Setup driver data for this window */ @@ -1559,7 +1556,7 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti SDL_Window **new_windows = (SDL_Window **)SDL_realloc(viddata->windows, new_max_windows * sizeof(SDL_Window *)); if (!new_windows) { - return SDL_OutOfMemory(); + return -1; } viddata->windows = new_windows; viddata->max_windows = new_max_windows; diff --git a/src/video/n3ds/SDL_n3dsframebuffer.c b/src/video/n3ds/SDL_n3dsframebuffer.c index 727dab6a8..099306210 100644 --- a/src/video/n3ds/SDL_n3dsframebuffer.c +++ b/src/video/n3ds/SDL_n3dsframebuffer.c @@ -54,7 +54,7 @@ int SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, framebuffer = SDL_CreateSurface(w, h, FRAMEBUFFER_FORMAT); if (!framebuffer) { - return SDL_OutOfMemory(); + return -1; } SDL_SetPropertyWithCleanup(SDL_GetWindowProperties(window), N3DS_SURFACE, framebuffer, CleanupSurface, NULL); diff --git a/src/video/n3ds/SDL_n3dsvideo.c b/src/video/n3ds/SDL_n3dsvideo.c index 6eb88ec3d..4e55642fe 100644 --- a/src/video/n3ds/SDL_n3dsvideo.c +++ b/src/video/n3ds/SDL_n3dsvideo.c @@ -56,7 +56,6 @@ static SDL_VideoDevice *N3DS_CreateDevice(void) { SDL_VideoDevice *device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return 0; } @@ -105,7 +104,7 @@ static int AddN3DSDisplay(gfxScreen_t screen) SDL_VideoDisplay display; SDL_DisplayData *display_driver_data = SDL_calloc(1, sizeof(SDL_DisplayData)); if (!display_driver_data) { - return SDL_OutOfMemory(); + return -1; } SDL_zero(mode); @@ -155,7 +154,7 @@ static int N3DS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Pro SDL_DisplayData *display_data; SDL_WindowData *window_data = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!window_data) { - return SDL_OutOfMemory(); + return -1; } display_data = SDL_GetDisplayDriverDataForWindow(window); window_data->screen = display_data->screen; diff --git a/src/video/ngage/SDL_ngagevideo.cpp b/src/video/ngage/SDL_ngagevideo.cpp index d9af15d27..5d30d4225 100644 --- a/src/video/ngage/SDL_ngagevideo.cpp +++ b/src/video/ngage/SDL_ngagevideo.cpp @@ -105,14 +105,12 @@ static SDL_VideoDevice *NGAGE_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return 0; } /* Initialize internal N-Gage specific data */ phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); if (!phdata) { - SDL_OutOfMemory(); SDL_free(device); return 0; } diff --git a/src/video/ngage/SDL_ngagewindow.cpp b/src/video/ngage/SDL_ngagewindow.cpp index 7a305ec33..44296e1f0 100644 --- a/src/video/ngage/SDL_ngagewindow.cpp +++ b/src/video/ngage/SDL_ngagewindow.cpp @@ -37,7 +37,7 @@ int NGAGE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie NGAGE_Window *ngage_window = (NGAGE_Window *)SDL_calloc(1, sizeof(NGAGE_Window)); if (!ngage_window) { - return SDL_OutOfMemory(); + return -1; } window->driverdata = ngage_window; diff --git a/src/video/offscreen/SDL_offscreenvideo.c b/src/video/offscreen/SDL_offscreenvideo.c index f4955862a..2b66260bd 100644 --- a/src/video/offscreen/SDL_offscreenvideo.c +++ b/src/video/offscreen/SDL_offscreenvideo.c @@ -57,7 +57,6 @@ static SDL_VideoDevice *OFFSCREEN_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return 0; } diff --git a/src/video/offscreen/SDL_offscreenwindow.c b/src/video/offscreen/SDL_offscreenwindow.c index f90bba682..a51f8fd36 100644 --- a/src/video/offscreen/SDL_offscreenwindow.c +++ b/src/video/offscreen/SDL_offscreenwindow.c @@ -32,7 +32,7 @@ int OFFSCREEN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Prope SDL_WindowData *offscreen_window = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!offscreen_window) { - return SDL_OutOfMemory(); + return -1; } window->driverdata = offscreen_window; diff --git a/src/video/ps2/SDL_ps2video.c b/src/video/ps2/SDL_ps2video.c index ea12f7cbd..273e97784 100644 --- a/src/video/ps2/SDL_ps2video.c +++ b/src/video/ps2/SDL_ps2video.c @@ -96,7 +96,6 @@ static SDL_VideoDevice *PS2_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return 0; } diff --git a/src/video/psp/SDL_pspvideo.c b/src/video/psp/SDL_pspvideo.c index 27f9b47db..95d0d387c 100644 --- a/src/video/psp/SDL_pspvideo.c +++ b/src/video/psp/SDL_pspvideo.c @@ -52,21 +52,18 @@ static SDL_VideoDevice *PSP_Create() /* Initialize SDL_VideoDevice structure */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return NULL; } /* Initialize internal PSP specific data */ phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); if (!phdata) { - SDL_OutOfMemory(); SDL_free(device); return NULL; } gldata = (SDL_GLDriverData *)SDL_calloc(1, sizeof(SDL_GLDriverData)); if (!gldata) { - SDL_OutOfMemory(); SDL_free(device); SDL_free(phdata); return NULL; @@ -197,7 +194,7 @@ int PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI /* Allocate window internal data */ wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!wdata) { - return SDL_OutOfMemory(); + return -1; } /* Setup driver data for this window */ diff --git a/src/video/raspberry/SDL_rpimouse.c b/src/video/raspberry/SDL_rpimouse.c index 1d915270c..1bd8f839b 100644 --- a/src/video/raspberry/SDL_rpimouse.c +++ b/src/video/raspberry/SDL_rpimouse.c @@ -66,12 +66,10 @@ static SDL_Cursor *RPI_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) cursor = (SDL_Cursor *)SDL_calloc(1, sizeof(*cursor)); if (!cursor) { - SDL_OutOfMemory(); return NULL; } curdata = (RPI_CursorData *)SDL_calloc(1, sizeof(*curdata)); if (!curdata) { - SDL_OutOfMemory(); SDL_free(cursor); return NULL; } diff --git a/src/video/raspberry/SDL_rpivideo.c b/src/video/raspberry/SDL_rpivideo.c index 5b1c45ad0..25efc514c 100644 --- a/src/video/raspberry/SDL_rpivideo.c +++ b/src/video/raspberry/SDL_rpivideo.c @@ -77,14 +77,12 @@ static SDL_VideoDevice *RPI_Create() /* Initialize SDL_VideoDevice structure */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return NULL; } /* Initialize internal data */ phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); if (!phdata) { - SDL_OutOfMemory(); SDL_free(device); return NULL; } @@ -236,7 +234,7 @@ int RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI /* Allocate window internal data */ wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!wdata) { - return SDL_OutOfMemory(); + return -1; } display = SDL_GetVideoDisplayForWindow(window); displaydata = display->driverdata; diff --git a/src/video/riscos/SDL_riscosframebuffer.c b/src/video/riscos/SDL_riscosframebuffer.c index 1f53f85af..9a884c86f 100644 --- a/src/video/riscos/SDL_riscosframebuffer.c +++ b/src/video/riscos/SDL_riscosframebuffer.c @@ -63,7 +63,7 @@ int RISCOS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, U size = sizeof(sprite_area) + sizeof(sprite_header) + ((*pitch) * h); driverdata->fb_area = SDL_malloc(size); if (!driverdata->fb_area) { - return SDL_OutOfMemory(); + return -1; } driverdata->fb_area->size = size; diff --git a/src/video/riscos/SDL_riscosmodes.c b/src/video/riscos/SDL_riscosmodes.c index d5cb44752..eb0aa4bc6 100644 --- a/src/video/riscos/SDL_riscosmodes.c +++ b/src/video/riscos/SDL_riscosmodes.c @@ -220,7 +220,7 @@ int RISCOS_InitModes(SDL_VideoDevice *_this) size = measure_mode_block(current_mode); mode.driverdata = copy_memory(current_mode, size, size); if (!mode.driverdata) { - return SDL_OutOfMemory(); + return -1; } if (SDL_AddBasicVideoDisplay(&mode) == 0) { @@ -247,7 +247,7 @@ int RISCOS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) block = SDL_malloc(-regs.r[7]); if (!block) { - return SDL_OutOfMemory(); + return -1; } regs.r[6] = (int)block; @@ -270,7 +270,7 @@ int RISCOS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) mode.driverdata = convert_mode_block(pos + 4); if (!mode.driverdata) { SDL_free(block); - return SDL_OutOfMemory(); + return -1; } if (!SDL_AddFullscreenDisplayMode(display, &mode)) { diff --git a/src/video/riscos/SDL_riscosmouse.c b/src/video/riscos/SDL_riscosmouse.c index 40b7cf2bb..de31bcdcf 100644 --- a/src/video/riscos/SDL_riscosmouse.c +++ b/src/video/riscos/SDL_riscosmouse.c @@ -30,14 +30,10 @@ static SDL_Cursor *RISCOS_CreateDefaultCursor() { - SDL_Cursor *cursor; - - cursor = SDL_calloc(1, sizeof(*cursor)); + SDL_Cursor *cursor = SDL_calloc(1, sizeof(*cursor)); if (cursor) { /* NULL is used to indicate the default cursor */ cursor->driverdata = NULL; - } else { - SDL_OutOfMemory(); } return cursor; diff --git a/src/video/riscos/SDL_riscosvideo.c b/src/video/riscos/SDL_riscosvideo.c index d132abdb8..399d6ce07 100644 --- a/src/video/riscos/SDL_riscosvideo.c +++ b/src/video/riscos/SDL_riscosvideo.c @@ -55,14 +55,12 @@ static SDL_VideoDevice *RISCOS_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return 0; } /* Initialize internal data */ phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); if (!phdata) { - SDL_OutOfMemory(); SDL_free(device); return NULL; } diff --git a/src/video/riscos/SDL_riscoswindow.c b/src/video/riscos/SDL_riscoswindow.c index 2b27bf7f7..aceb378a2 100644 --- a/src/video/riscos/SDL_riscoswindow.c +++ b/src/video/riscos/SDL_riscoswindow.c @@ -34,7 +34,7 @@ int RISCOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti driverdata = (SDL_WindowData *)SDL_calloc(1, sizeof(*driverdata)); if (!driverdata) { - return SDL_OutOfMemory(); + return -1; } driverdata->window = window; diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m index 0c37b3342..3b751d521 100644 --- a/src/video/uikit/SDL_uikitvideo.m +++ b/src/video/uikit/SDL_uikitvideo.m @@ -67,13 +67,11 @@ static SDL_VideoDevice *UIKit_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (device) { - data = [SDL_UIKitVideoData new]; - } else { - SDL_free(device); - SDL_OutOfMemory(); - return (0); - } + if (!device) { + return NULL; + ] + + data = [SDL_UIKitVideoData new]; device->driverdata = (SDL_VideoData *)CFBridgingRetain(data); device->system_theme = UIKit_GetSystemTheme(); diff --git a/src/video/vita/SDL_vitavideo.c b/src/video/vita/SDL_vitavideo.c index efaa6209a..8c0fad1ea 100644 --- a/src/video/vita/SDL_vitavideo.c +++ b/src/video/vita/SDL_vitavideo.c @@ -68,14 +68,12 @@ static SDL_VideoDevice *VITA_Create() /* Initialize SDL_VideoDevice structure */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return NULL; } /* Initialize internal VITA specific data */ phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); if (!phdata) { - SDL_OutOfMemory(); SDL_free(device); return NULL; } @@ -83,7 +81,6 @@ static SDL_VideoDevice *VITA_Create() gldata = (SDL_GLDriverData *)SDL_calloc(1, sizeof(SDL_GLDriverData)); if (!gldata) { - SDL_OutOfMemory(); SDL_free(device); SDL_free(phdata); return NULL; @@ -231,7 +228,7 @@ int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properties /* Allocate window internal data */ wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!wdata) { - return SDL_OutOfMemory(); + return -1; } /* Setup driver data for this window */ diff --git a/src/video/vivante/SDL_vivantevideo.c b/src/video/vivante/SDL_vivantevideo.c index f9d2daa2e..3a6f56e16 100644 --- a/src/video/vivante/SDL_vivantevideo.c +++ b/src/video/vivante/SDL_vivantevideo.c @@ -49,14 +49,12 @@ static SDL_VideoDevice *VIVANTE_Create() /* Initialize SDL_VideoDevice structure */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return NULL; } /* Initialize internal data */ data = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); if (!data) { - SDL_OutOfMemory(); SDL_free(device); return NULL; } @@ -125,7 +123,7 @@ static int VIVANTE_AddVideoDisplays(SDL_VideoDevice *_this) data = (SDL_DisplayData *)SDL_calloc(1, sizeof(SDL_DisplayData)); if (!data) { - return SDL_OutOfMemory(); + return -1; } SDL_zero(mode); @@ -249,7 +247,7 @@ int VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert /* Allocate window internal data */ data = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!data) { - return SDL_OutOfMemory(); + return -1; } /* Setup driver data for this window */ diff --git a/src/video/wayland/SDL_waylanddatamanager.c b/src/video/wayland/SDL_waylanddatamanager.c index 00da37305..9d9808e65 100644 --- a/src/video/wayland/SDL_waylanddatamanager.c +++ b/src/video/wayland/SDL_waylanddatamanager.c @@ -119,7 +119,7 @@ static ssize_t read_pipe(int fd, void **buffer, size_t *total_length) } if (!output_buffer) { - bytes_read = SDL_OutOfMemory(); + bytes_read = -1; } else { SDL_memcpy((Uint8 *)output_buffer + pos, temp, bytes_read); SDL_memset((Uint8 *)output_buffer + (new_buffer_length - sizeof(Uint32)), 0, sizeof(Uint32)); @@ -158,7 +158,7 @@ static int mime_data_list_add(struct wl_list *list, if (buffer) { internal_buffer = SDL_malloc(length); if (!internal_buffer) { - return SDL_OutOfMemory(); + return -1; } SDL_memcpy(internal_buffer, buffer, length); } @@ -168,14 +168,14 @@ static int mime_data_list_add(struct wl_list *list, if (!mime_data) { mime_data = SDL_calloc(1, sizeof(*mime_data)); if (!mime_data) { - status = SDL_OutOfMemory(); + status = -1; } else { WAYLAND_wl_list_insert(list, &(mime_data->link)); mime_type_length = SDL_strlen(mime_type) + 1; mime_data->mime_type = SDL_malloc(mime_type_length); if (!mime_data->mime_type) { - status = SDL_OutOfMemory(); + status = -1; } else { SDL_memcpy(mime_data->mime_type, mime_type, mime_type_length); } @@ -278,9 +278,7 @@ static void *Wayland_clone_data_buffer(const void *buffer, size_t *len) void *clone = NULL; if (*len > 0 && buffer) { clone = SDL_malloc((*len)+sizeof(Uint32)); - if (!clone) { - SDL_OutOfMemory(); - } else { + if (clone) { SDL_memcpy(clone, buffer, *len); SDL_memset((Uint8 *)clone + *len, 0, sizeof(Uint32)); } diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index e8eb58be2..ebdf546d5 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -1765,7 +1765,6 @@ SDL_WaylandDataSource *Wayland_data_source_create(SDL_VideoDevice *_this) } else { data_source = SDL_calloc(1, sizeof(*data_source)); if (!data_source) { - SDL_OutOfMemory(); wl_data_source_destroy(id); } else { data_source->source = id; @@ -1799,7 +1798,6 @@ SDL_WaylandPrimarySelectionSource *Wayland_primary_selection_source_create(SDL_V } else { primary_selection_source = SDL_calloc(1, sizeof(*primary_selection_source)); if (!primary_selection_source) { - SDL_OutOfMemory(); zwp_primary_selection_source_v1_destroy(id); } else { primary_selection_source->source = id; @@ -1848,12 +1846,8 @@ static const struct zwp_primary_selection_offer_v1_listener primary_selection_of static void data_device_handle_data_offer(void *data, struct wl_data_device *wl_data_device, struct wl_data_offer *id) { - SDL_WaylandDataOffer *data_offer = NULL; - - data_offer = SDL_calloc(1, sizeof(*data_offer)); - if (!data_offer) { - SDL_OutOfMemory(); - } else { + SDL_WaylandDataOffer *data_offer = SDL_calloc(1, sizeof(*data_offer)); + if (data_offer) { data_offer->offer = id; data_offer->data_device = data; WAYLAND_wl_list_init(&(data_offer->mimes)); @@ -2158,12 +2152,8 @@ static const struct wl_data_device_listener data_device_listener = { static void primary_selection_device_handle_offer(void *data, struct zwp_primary_selection_device_v1 *zwp_primary_selection_device_v1, struct zwp_primary_selection_offer_v1 *id) { - SDL_WaylandPrimarySelectionOffer *primary_selection_offer = NULL; - - primary_selection_offer = SDL_calloc(1, sizeof(*primary_selection_offer)); - if (!primary_selection_offer) { - SDL_OutOfMemory(); - } else { + SDL_WaylandPrimarySelectionOffer *primary_selection_offer = SDL_calloc(1, sizeof(*primary_selection_offer)); + if (primary_selection_offer) { primary_selection_offer->offer = id; primary_selection_offer->primary_selection_device = data; WAYLAND_wl_list_init(&(primary_selection_offer->mimes)); diff --git a/src/video/wayland/SDL_waylandmessagebox.c b/src/video/wayland/SDL_waylandmessagebox.c index 2fda9eef9..2af96ddec 100644 --- a/src/video/wayland/SDL_waylandmessagebox.c +++ b/src/video/wayland/SDL_waylandmessagebox.c @@ -223,7 +223,7 @@ int Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *button output = SDL_malloc(output_len + 1); if (!output) { close(fd_pipe[0]); - return SDL_OutOfMemory(); + return -1; } output[0] = '\0'; diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c index 7012c2fb1..c670cdc18 100644 --- a/src/video/wayland/SDL_waylandmouse.c +++ b/src/video/wayland/SDL_waylandmouse.c @@ -302,7 +302,6 @@ static SDL_bool wayland_get_system_cursor(SDL_VideoData *vdata, Wayland_CursorDa SDL_WaylandCursorTheme *new_cursor_themes = SDL_realloc(vdata->cursor_themes, sizeof(SDL_WaylandCursorTheme) * (vdata->num_cursor_themes + 1)); if (!new_cursor_themes) { - SDL_OutOfMemory(); return SDL_FALSE; } vdata->cursor_themes = new_cursor_themes; @@ -504,15 +503,12 @@ static int create_buffer_from_shm(Wayland_CursorData *d, static SDL_Cursor *Wayland_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) { - SDL_Cursor *cursor; - - cursor = SDL_calloc(1, sizeof(*cursor)); + SDL_Cursor *cursor = SDL_calloc(1, sizeof(*cursor)); if (cursor) { SDL_VideoDevice *vd = SDL_GetVideoDevice(); SDL_VideoData *wd = vd->driverdata; Wayland_CursorData *data = SDL_calloc(1, sizeof(Wayland_CursorData)); if (!data) { - SDL_OutOfMemory(); SDL_free(cursor); return NULL; } @@ -540,8 +536,6 @@ static SDL_Cursor *Wayland_CreateCursor(SDL_Surface *surface, int hot_x, int hot data->hot_y = hot_y; data->w = surface->w; data->h = surface->h; - } else { - SDL_OutOfMemory(); } return cursor; @@ -550,13 +544,10 @@ static SDL_Cursor *Wayland_CreateCursor(SDL_Surface *surface, int hot_x, int hot static SDL_Cursor *Wayland_CreateSystemCursor(SDL_SystemCursor id) { SDL_VideoData *data = SDL_GetVideoDevice()->driverdata; - SDL_Cursor *cursor; - - cursor = SDL_calloc(1, sizeof(*cursor)); + SDL_Cursor *cursor = SDL_calloc(1, sizeof(*cursor)); if (cursor) { Wayland_CursorData *cdata = SDL_calloc(1, sizeof(Wayland_CursorData)); if (!cdata) { - SDL_OutOfMemory(); SDL_free(cursor); return NULL; } @@ -569,8 +560,6 @@ static SDL_Cursor *Wayland_CreateSystemCursor(SDL_SystemCursor id) * is output-specific. See wayland_get_system_cursor for the rest! */ cdata->system_cursor = id; - } else { - SDL_OutOfMemory(); } return cursor; diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c index dfcf717c6..55b403aec 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -149,7 +149,6 @@ static SDL_VideoDevice *Wayland_CreateDevice(void) if (!data) { WAYLAND_wl_display_disconnect(display); SDL_WAYLAND_UnloadSymbols(); - SDL_OutOfMemory(); return NULL; } @@ -163,7 +162,6 @@ static SDL_VideoDevice *Wayland_CreateDevice(void) SDL_free(data); WAYLAND_wl_display_disconnect(display); SDL_WAYLAND_UnloadSymbols(); - SDL_OutOfMemory(); return NULL; } diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c index ad2ce5c41..ce7a383ea 100644 --- a/src/video/wayland/SDL_waylandwindow.c +++ b/src/video/wayland/SDL_waylandwindow.c @@ -1988,7 +1988,7 @@ int Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert data = SDL_calloc(1, sizeof(*data)); if (!data) { - return SDL_OutOfMemory(); + return -1; } c = _this->driverdata; diff --git a/src/video/windows/SDL_windowsclipboard.c b/src/video/windows/SDL_windowsclipboard.c index 933cce029..8a1e4a427 100644 --- a/src/video/windows/SDL_windowsclipboard.c +++ b/src/video/windows/SDL_windowsclipboard.c @@ -125,8 +125,6 @@ static void *WIN_ConvertDIBtoBMP(HANDLE hMem, size_t *size) pbfh->bfOffBits = (DWORD)(sizeof(BITMAPFILEHEADER) + bih_size); SDL_memcpy((Uint8 *)bmp + sizeof(BITMAPFILEHEADER), dib, dib_size); *size = bmp_size; - } else { - SDL_OutOfMemory(); } } else { SDL_SetError("Invalid BMP data"); diff --git a/src/video/windows/SDL_windowsframebuffer.c b/src/video/windows/SDL_windowsframebuffer.c index 9be7cc83b..d20475779 100644 --- a/src/video/windows/SDL_windowsframebuffer.c +++ b/src/video/windows/SDL_windowsframebuffer.c @@ -47,7 +47,7 @@ int WIN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, Uint size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD); info = (LPBITMAPINFO)SDL_small_alloc(Uint8, size, &isstack); if (!info) { - return SDL_OutOfMemory(); + return -1; } SDL_memset(info, 0, size); diff --git a/src/video/windows/SDL_windowsmessagebox.c b/src/video/windows/SDL_windowsmessagebox.c index 689121c2a..19b48f24c 100644 --- a/src/video/windows/SDL_windowsmessagebox.c +++ b/src/video/windows/SDL_windowsmessagebox.c @@ -345,7 +345,6 @@ static SDL_bool ExpandDialogSpace(WIN_DialogData *dialog, size_t space) if (size > dialog->size) { void *data = SDL_realloc(dialog->data, size); if (!data) { - SDL_OutOfMemory(); return SDL_FALSE; } dialog->data = data; diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c index 6bd9515b6..21e19685b 100644 --- a/src/video/windows/SDL_windowsmouse.c +++ b/src/video/windows/SDL_windowsmouse.c @@ -72,13 +72,9 @@ static int ToggleRawInput(SDL_bool enabled) static SDL_Cursor *WIN_CreateDefaultCursor() { - SDL_Cursor *cursor; - - cursor = SDL_calloc(1, sizeof(*cursor)); + SDL_Cursor *cursor = SDL_calloc(1, sizeof(*cursor)); if (cursor) { cursor->driverdata = LoadCursor(NULL, IDC_ARROW); - } else { - SDL_OutOfMemory(); } return cursor; @@ -125,7 +121,6 @@ static HBITMAP CreateMaskBitmap(SDL_Surface *surface) pixels = SDL_small_alloc(Uint8, pitch * surface->h, &isstack); if (!pixels) { - SDL_OutOfMemory(); return NULL; } @@ -190,7 +185,6 @@ static SDL_Cursor *WIN_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) cursor->driverdata = hcursor; } else { DestroyCursor(hcursor); - SDL_OutOfMemory(); } return cursor; @@ -285,8 +279,6 @@ static SDL_Cursor *WIN_CreateSystemCursor(SDL_SystemCursor id) hcursor = LoadCursor(NULL, name); cursor->driverdata = hcursor; - } else { - SDL_OutOfMemory(); } return cursor; diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c index 9216b6c7b..5846b26ae 100644 --- a/src/video/windows/SDL_windowsopengl.c +++ b/src/video/windows/SDL_windowsopengl.c @@ -125,7 +125,7 @@ int WIN_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) /* Allocate OpenGL memory */ _this->gl_data = (struct SDL_GLDriverData *)SDL_calloc(1, sizeof(struct SDL_GLDriverData)); if (!_this->gl_data) { - return SDL_OutOfMemory(); + return -1; } /* Load function pointers */ diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 6cfbc35d2..9d6330f7a 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -117,7 +117,6 @@ static SDL_VideoDevice *WIN_CreateDevice(void) } if (!data) { SDL_free(device); - SDL_OutOfMemory(); return NULL; } device->driverdata = data; diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index 55e2d700e..43dc5a717 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -283,7 +283,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd /* Allocate the window data */ data = (SDL_WindowData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return SDL_OutOfMemory(); + return -1; } data->window = window; data->hwnd = hwnd; @@ -1157,8 +1157,6 @@ void *WIN_GetWindowICCProfile(SDL_VideoDevice *_this, SDL_Window *window, size_t SDL_SetError("Could not open ICC profile"); } SDL_free(filename_utf8); - } else { - SDL_OutOfMemory(); } return iccProfileData; } diff --git a/src/video/winrt/SDL_winrtmouse.cpp b/src/video/winrt/SDL_winrtmouse.cpp index 30ebfbcb5..b46c88985 100644 --- a/src/video/winrt/SDL_winrtmouse.cpp +++ b/src/video/winrt/SDL_winrtmouse.cpp @@ -126,8 +126,6 @@ static SDL_Cursor *WINRT_CreateSystemCursor(SDL_SystemCursor id) CoreCursor ^ *theCursor = new CoreCursor ^ (nullptr); *theCursor = ref new CoreCursor(cursorType, 0); cursor->driverdata = (void *)theCursor; - } else { - SDL_OutOfMemory(); } return cursor; diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp index 8f8cde7e5..8f6572c89 100644 --- a/src/video/winrt/SDL_winrtvideo.cpp +++ b/src/video/winrt/SDL_winrtvideo.cpp @@ -109,13 +109,11 @@ static SDL_VideoDevice *WINRT_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return 0; } data = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); if (!data) { - SDL_OutOfMemory(); SDL_free(device); return 0; } @@ -321,7 +319,6 @@ static int WINRT_AddDisplaysForOutput(SDL_VideoDevice *_this, IDXGIAdapter1 *dxg dxgiModes = (DXGI_MODE_DESC *)SDL_calloc(numModes, sizeof(DXGI_MODE_DESC)); if (!dxgiModes) { - SDL_OutOfMemory(); goto done; } diff --git a/src/video/x11/SDL_x11clipboard.c b/src/video/x11/SDL_x11clipboard.c index 4bb7d395b..708d01d10 100644 --- a/src/video/x11/SDL_x11clipboard.c +++ b/src/video/x11/SDL_x11clipboard.c @@ -101,9 +101,7 @@ static void *CloneDataBuffer(const void *buffer, size_t *len) void *clone = NULL; if (*len > 0 && buffer) { clone = SDL_malloc((*len)+sizeof(Uint32)); - if (!clone) { - SDL_OutOfMemory(); - } else { + if (clone) { SDL_memcpy(clone, buffer, *len); SDL_memset((Uint8 *)clone + *len, 0, sizeof(Uint32)); } diff --git a/src/video/x11/SDL_x11framebuffer.c b/src/video/x11/SDL_x11framebuffer.c index b4a0ae12a..6714a1feb 100644 --- a/src/video/x11/SDL_x11framebuffer.c +++ b/src/video/x11/SDL_x11framebuffer.c @@ -128,7 +128,7 @@ int X11_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, Uint *pixels = SDL_malloc((size_t)h * (*pitch)); if (!*pixels) { - return SDL_OutOfMemory(); + return -1; } data->ximage = X11_XCreateImage(display, data->visual, diff --git a/src/video/x11/SDL_x11messagebox.c b/src/video/x11/SDL_x11messagebox.c index 7eae41deb..2367b9449 100644 --- a/src/video/x11/SDL_x11messagebox.c +++ b/src/video/x11/SDL_x11messagebox.c @@ -245,7 +245,7 @@ static int X11_MessageBoxInitPositions(SDL_MessageBoxDataX11 *data) TextLineData *plinedata = (TextLineData *)SDL_malloc(sizeof(TextLineData) * linecount); if (!plinedata) { - return SDL_OutOfMemory(); + return -1; } data->linedata = plinedata; @@ -763,7 +763,7 @@ static int X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int if (origlocale) { origlocale = SDL_strdup(origlocale); if (!origlocale) { - return SDL_OutOfMemory(); + return -1; } (void)setlocale(LC_ALL, ""); } diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index 16255c98e..15e681766 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -565,13 +565,13 @@ static int X11_AddXRandRDisplay(SDL_VideoDevice *_this, Display *dpy, int screen displaydata = (SDL_DisplayData *)SDL_calloc(1, sizeof(*displaydata)); if (!displaydata) { - return SDL_OutOfMemory(); + return -1; } modedata = (SDL_DisplayModeData *)SDL_calloc(1, sizeof(SDL_DisplayModeData)); if (!modedata) { SDL_free(displaydata); - return SDL_OutOfMemory(); + return -1; } modedata->xrandr_mode = modeID; @@ -768,13 +768,13 @@ static int X11_InitModes_StdXlib(SDL_VideoDevice *_this) displaydata = (SDL_DisplayData *)SDL_calloc(1, sizeof(*displaydata)); if (!displaydata) { - return SDL_OutOfMemory(); + return -1; } modedata = (SDL_DisplayModeData *)SDL_calloc(1, sizeof(SDL_DisplayModeData)); if (!modedata) { SDL_free(displaydata); - return SDL_OutOfMemory(); + return -1; } mode.driverdata = modedata; diff --git a/src/video/x11/SDL_x11mouse.c b/src/video/x11/SDL_x11mouse.c index 980aed60a..9c32b12f8 100644 --- a/src/video/x11/SDL_x11mouse.c +++ b/src/video/x11/SDL_x11mouse.c @@ -69,14 +69,10 @@ static void X11_DestroyEmptyCursor(void) static SDL_Cursor *X11_CreateDefaultCursor(void) { - SDL_Cursor *cursor; - - cursor = SDL_calloc(1, sizeof(*cursor)); + SDL_Cursor *cursor = SDL_calloc(1, sizeof(*cursor)); if (cursor) { /* None is used to indicate the default cursor */ cursor->driverdata = (void *)(uintptr_t)None; - } else { - SDL_OutOfMemory(); } return cursor; @@ -124,14 +120,12 @@ static Cursor X11_CreatePixmapCursor(SDL_Surface *surface, int hot_x, int hot_y) data_bits = SDL_calloc(1, surface->h * width_bytes); if (!data_bits) { - SDL_OutOfMemory(); return None; } mask_bits = SDL_calloc(1, surface->h * width_bytes); if (!mask_bits) { SDL_free(data_bits); - SDL_OutOfMemory(); return None; } @@ -200,9 +194,7 @@ static Cursor X11_CreatePixmapCursor(SDL_Surface *surface, int hot_x, int hot_y) static SDL_Cursor *X11_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) { - SDL_Cursor *cursor; - - cursor = SDL_calloc(1, sizeof(*cursor)); + SDL_Cursor *cursor = SDL_calloc(1, sizeof(*cursor)); if (cursor) { Cursor x11_cursor = None; @@ -215,8 +207,6 @@ static SDL_Cursor *X11_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) x11_cursor = X11_CreatePixmapCursor(surface, hot_x, hot_y); } cursor->driverdata = (void *)(uintptr_t)x11_cursor; - } else { - SDL_OutOfMemory(); } return cursor; @@ -302,8 +292,6 @@ static SDL_Cursor *X11_CreateSystemCursor(SDL_SystemCursor id) x11_cursor = X11_XCreateFontCursor(GetDisplay(), shape); cursor->driverdata = (void *)(uintptr_t)x11_cursor; - } else { - SDL_OutOfMemory(); } return cursor; diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index aad96462d..1d5edd895 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -193,7 +193,7 @@ int X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) sizeof(struct SDL_GLDriverData)); if (!_this->gl_data) { - return SDL_OutOfMemory(); + return -1; } /* Load function pointers */ diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 32a28ee1a..6bb5f5c63 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -123,13 +123,11 @@ static SDL_VideoDevice *X11_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); return NULL; } data = (struct SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); if (!data) { SDL_free(device); - SDL_OutOfMemory(); return NULL; } device->driverdata = data; diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 5d8000d21..8459d8619 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -312,7 +312,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w) /* Allocate the window data */ data = (SDL_WindowData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return SDL_OutOfMemory(); + return -1; } data->window = window; data->xwindow = w; @@ -337,7 +337,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w) SDL_WindowData ** new_windowlist = (SDL_WindowData **)SDL_realloc(windowlist, (numwindows + 1) * sizeof(*windowlist)); if (!new_windowlist) { SDL_free(data); - return SDL_OutOfMemory(); + return -1; } windowlist = new_windowlist; windowlist[numwindows] = data; @@ -543,7 +543,7 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI /* OK, we got a colormap, now fill it in as best as we can */ colorcells = SDL_malloc(visual->map_entries * sizeof(XColor)); if (!colorcells) { - return SDL_OutOfMemory(); + return -1; } ncolors = visual->map_entries; rmax = 0xffff; @@ -971,7 +971,7 @@ int X11_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *i propdata = SDL_malloc(propsize * sizeof(long)); if (!propdata) { - return SDL_OutOfMemory(); + return -1; } X11_XSync(display, False); @@ -1723,7 +1723,6 @@ void *X11_GetWindowICCProfile(SDL_VideoDevice *_this, SDL_Window *window, size_t ret_icc_profile_data = SDL_malloc(real_nitems); if (!ret_icc_profile_data) { - SDL_OutOfMemory(); return NULL; } diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c index ef97d33c3..4e8710c83 100644 --- a/src/video/x11/SDL_x11xinput2.c +++ b/src/video/x11/SDL_x11xinput2.c @@ -237,7 +237,6 @@ static SDL_XInput2DeviceInfo *xinput2_get_device_info(SDL_VideoData *videodata, /* don't know about this device yet, query and cache it. */ devinfo = (SDL_XInput2DeviceInfo *)SDL_calloc(1, sizeof(SDL_XInput2DeviceInfo)); if (!devinfo) { - SDL_OutOfMemory(); return NULL; } diff --git a/test/testffmpeg.c b/test/testffmpeg.c index f28d60c35..eadef4bd1 100644 --- a/test/testffmpeg.c +++ b/test/testffmpeg.c @@ -461,7 +461,6 @@ static SDL_bool GetTextureForMemoryFrame(AVFrame *frame, SDL_Texture **texture) if (!sws_container) { sws_container = (struct SwsContextContainer *)SDL_calloc(1, sizeof(*sws_container)); if (!sws_container) { - SDL_OutOfMemory(); return SDL_FALSE; } SDL_SetPropertyWithCleanup(props, SWS_CONTEXT_CONTAINER_PROPERTY, sws_container, FreeSwsContextContainer, NULL); @@ -587,8 +586,6 @@ static SDL_bool GetTextureForVAAPIFrame(AVFrame *frame, SDL_Texture **texture) SDL_SetError("Couldn't map hardware frame"); } av_frame_free(&drm_frame); - } else { - SDL_OutOfMemory(); } return result; } diff --git a/test/testshape.c b/test/testshape.c index 459badabe..e136bb28b 100644 --- a/test/testshape.c +++ b/test/testshape.c @@ -144,7 +144,7 @@ static int SDL3_SetWindowShape(SDL_Window *window, SDL_Surface *shape, SDL_Windo g_bitmap_h = shape->h; g_bitmap = (Uint8*) SDL_malloc(shape->w * shape->h); if (!g_bitmap) { - return SDL_OutOfMemory(); + return -1; } SDL_CalculateShapeBitmap(*shape_mode, shape, g_bitmap, 1); diff --git a/test/testutils.c b/test/testutils.c index e9d505297..7b99cc8b4 100644 --- a/test/testutils.c +++ b/test/testutils.c @@ -36,7 +36,6 @@ GetNearbyFilename(const char *file) if (!path) { SDL_free(base); - SDL_OutOfMemory(); return NULL; } @@ -53,11 +52,7 @@ GetNearbyFilename(const char *file) SDL_free(path); } - path = SDL_strdup(file); - if (!path) { - SDL_OutOfMemory(); - } - return path; + return SDL_strdup(file); } /** @@ -73,16 +68,9 @@ char * GetResourceFilename(const char *user_specified, const char *def) { if (user_specified) { - char *ret = SDL_strdup(user_specified); - - if (!ret) { - SDL_OutOfMemory(); - } - - return ret; - } else { - return GetNearbyFilename(def); + return SDL_strdup(user_specified); } + return GetNearbyFilename(def); } /** diff --git a/test/testvulkan.c b/test/testvulkan.c index 231e644ff..6cd805cc4 100644 --- a/test/testvulkan.c +++ b/test/testvulkan.c @@ -294,7 +294,6 @@ static void findPhysicalDevice(void) } physicalDevices = (VkPhysicalDevice *)SDL_malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount); if (!physicalDevices) { - SDL_OutOfMemory(); quit(2); } result = vkEnumeratePhysicalDevices(vulkanContext->instance, &physicalDeviceCount, physicalDevices); @@ -330,7 +329,6 @@ static void findPhysicalDevice(void) if (!queueFamiliesProperties) { SDL_free(physicalDevices); SDL_free(deviceExtensions); - SDL_OutOfMemory(); quit(2); } } @@ -392,7 +390,6 @@ static void findPhysicalDevice(void) if (!deviceExtensions) { SDL_free(physicalDevices); SDL_free(queueFamiliesProperties); - SDL_OutOfMemory(); quit(2); } } @@ -550,7 +547,6 @@ static void getSurfaceFormats(void) vulkanContext->surfaceFormats = (VkSurfaceFormatKHR *)SDL_malloc(sizeof(VkSurfaceFormatKHR) * vulkanContext->surfaceFormatsAllocatedCount); if (!vulkanContext->surfaceFormats) { vulkanContext->surfaceFormatsCount = 0; - SDL_OutOfMemory(); quit(2); } } @@ -583,7 +579,6 @@ static void getSwapchainImages(void) } vulkanContext->swapchainImages = SDL_malloc(sizeof(VkImage) * vulkanContext->swapchainImageCount); if (!vulkanContext->swapchainImages) { - SDL_OutOfMemory(); quit(2); } result = vkGetSwapchainImagesKHR(vulkanContext->device, @@ -763,7 +758,6 @@ static void createFences(void) vulkanContext->fences = SDL_malloc(sizeof(VkFence) * vulkanContext->swapchainImageCount); if (!vulkanContext->fences) { - SDL_OutOfMemory(); quit(2); } for (i = 0; i < vulkanContext->swapchainImageCount; i++) {