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.
main
Ryan C. Gordon 2023-11-30 00:14:27 -05:00
parent 70b65d4170
commit 447b508a77
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
197 changed files with 313 additions and 742 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -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) ||

View File

@ -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);

View File

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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

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

View File

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

View File

@ -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;
}
}

View File

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

View File

@ -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++) {

View File

@ -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);

View File

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

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -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

View File

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

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -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.
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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++;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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 */

View File

@ -46,7 +46,6 @@ SDL_GetBasePath(void)
void *ptr = SDL_realloc(path, buflen * sizeof(CHAR));
if (!ptr) {
SDL_free(path);
SDL_OutOfMemory();
return NULL;
}

View File

@ -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:

View File

@ -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;

View File

@ -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;
}

View File

@ -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";

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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 */

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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();

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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,

View File

@ -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! */

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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,

View File

@ -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) {

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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';

View File

@ -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)) {

View File

@ -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. */

View File

@ -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);

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -339,7 +339,6 @@ static id<MTLRenderPipelineState> MakePipelineState(METAL_RenderData *data, META
return (__bridge id<MTLRenderPipelineState>)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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

Some files were not shown because too many files have changed in this diff Show More