Mercurial > SDL_sound_CoreAudio
diff SDL_sound.c @ 172:705dcbf94639
Sound_DecodeAll() is now more robust.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 01 Dec 2001 01:12:58 +0000 |
parents | 82acaa7107c2 |
children | 47cc2de2ae36 |
line wrap: on
line diff
--- a/SDL_sound.c Sat Dec 01 01:12:40 2001 +0000 +++ b/SDL_sound.c Sat Dec 01 01:12:58 2001 +0000 @@ -638,17 +638,19 @@ { Sound_SampleInternal *internal = NULL; void *buf = NULL; - void *ptr; Uint32 newBufSize = 0; BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); + BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_EOF, ERR_PREV_EOF, 0); + BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_PREV_ERROR, 0); internal = (Sound_SampleInternal *) sample->opaque; while ( ((sample->flags & SOUND_SAMPLEFLAG_EOF) == 0) && ((sample->flags & SOUND_SAMPLEFLAG_ERROR) == 0) ) { - ptr = realloc(buf, newBufSize + sample->buffer_size); + Uint32 br = Sound_Decode(sample); + void *ptr = realloc(buf, newBufSize + br); if (ptr == NULL) { sample->flags |= SOUND_SAMPLEFLAG_ERROR; @@ -656,14 +658,15 @@ } /* if */ else { - Uint32 br; buf = ptr; - br = Sound_Decode(sample); memcpy( ((char *) buf) + newBufSize, sample->buffer, br ); newBufSize += br; } /* else */ } /* while */ + if (buf == NULL) /* ...in case first call to realloc() fails... */ + return(sample->buffer_size); + if (internal->buffer != sample->buffer) free(internal->buffer);