Make SDL_SetError and friends unconditionally return -1.

This lets us change things like this...

    if (Failed) {
        SDL_SetError("We failed");
        return -1;
    }

...into this...

    if (Failed) {
        return SDL_SetError("We failed");
    }


 Fixes Bugzilla #1778.
This commit is contained in:
Ryan C. Gordon 2013-03-31 12:48:50 -04:00
parent 8c6b9f4743
commit 4f438b70a2
106 changed files with 616 additions and 1189 deletions

View file

@ -970,28 +970,23 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
/* Sanity check target pointer */
if (cvt == NULL) {
SDL_InvalidParamError("cvt");
return -1;
return SDL_InvalidParamError("cvt");
}
/* there are no unsigned types over 16 bits, so catch this up front. */
if ((SDL_AUDIO_BITSIZE(src_fmt) > 16) && (!SDL_AUDIO_ISSIGNED(src_fmt))) {
SDL_SetError("Invalid source format");
return -1;
return SDL_SetError("Invalid source format");
}
if ((SDL_AUDIO_BITSIZE(dst_fmt) > 16) && (!SDL_AUDIO_ISSIGNED(dst_fmt))) {
SDL_SetError("Invalid destination format");
return -1;
return SDL_SetError("Invalid destination format");
}
/* prevent possible divisions by zero, etc. */
if ((src_channels == 0) || (dst_channels == 0)) {
SDL_SetError("Source or destination channels is zero");
return -1;
return SDL_SetError("Source or destination channels is zero");
}
if ((src_rate == 0) || (dst_rate == 0)) {
SDL_SetError("Source or destination rate is zero");
return -1;
return SDL_SetError("Source or destination rate is zero");
}
#ifdef DEBUG_CONVERT
printf("Build format %04x->%04x, channels %u->%u, rate %d->%d\n",

View file

@ -134,8 +134,7 @@ MS_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len)
MS_ADPCM_state.wavefmt.channels * sizeof(Sint16);
*audio_buf = (Uint8 *) SDL_malloc(*audio_len);
if (*audio_buf == NULL) {
SDL_Error(SDL_ENOMEM);
return (-1);
return SDL_OutOfMemory();
}
decoded = *audio_buf;
@ -359,8 +358,7 @@ IMA_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len)
IMA_ADPCM_state.wavefmt.channels * sizeof(Sint16);
*audio_buf = (Uint8 *) SDL_malloc(*audio_len);
if (*audio_buf == NULL) {
SDL_Error(SDL_ENOMEM);
return (-1);
return SDL_OutOfMemory();
}
decoded = *audio_buf;
@ -620,14 +618,12 @@ ReadChunk(SDL_RWops * src, Chunk * chunk)
chunk->length = SDL_ReadLE32(src);
chunk->data = (Uint8 *) SDL_malloc(chunk->length);
if (chunk->data == NULL) {
SDL_Error(SDL_ENOMEM);
return (-1);
return SDL_OutOfMemory();
}
if (SDL_RWread(src, chunk->data, chunk->length, 1) != 1) {
SDL_Error(SDL_EFREAD);
SDL_free(chunk->data);
chunk->data = NULL;
return (-1);
return SDL_Error(SDL_EFREAD);
}
return (chunk->length);
}

View file

@ -95,7 +95,7 @@ utf16_to_utf8(const WCHAR *S)
(SDL_wcslen(S)+1)*sizeof(WCHAR));
}
static void
static int
SetDSerror(const char *function, int code)
{
static const char *error;
@ -145,8 +145,7 @@ SetDSerror(const char *function, int code)
SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function,
error);
}
SDL_SetError("%s", errbuf);
return;
return SDL_SetError("%s", errbuf);
}
@ -380,16 +379,14 @@ CreateSecondary(_THIS, HWND focus, WAVEFORMATEX * wavefmt)
format.dwBufferBytes = numchunks * chunksize;
if ((format.dwBufferBytes < DSBSIZE_MIN) ||
(format.dwBufferBytes > DSBSIZE_MAX)) {
SDL_SetError("Sound buffer size must be between %d and %d",
DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks);
return (-1);
return SDL_SetError("Sound buffer size must be between %d and %d",
DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks);
}
format.dwReserved = 0;
format.lpwfxFormat = wavefmt;
result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL);
if (result != DS_OK) {
SetDSerror("DirectSound CreateSoundBuffer", result);
return (-1);
return SetDSerror("DirectSound CreateSoundBuffer", result);
}
IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt);

View file

@ -332,8 +332,7 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->frequency = 8;
this->hidden->ulaw_buf = (Uint8 *) SDL_malloc(this->hidden->fragsize);
if (this->hidden->ulaw_buf == NULL) {
SDL_OutOfMemory();
return (-1);
return SDL_OutOfMemory();
}
this->spec.channels = 1;
} else {
@ -353,8 +352,7 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
/* Allocate mixing buffer */
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->spec.size);
if (this->hidden->mixbuf == NULL) {
SDL_OutOfMemory();
return (-1);
return SDL_OutOfMemory();
}
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);