# HG changeset patch # User Ryan C. Gordon # Date 1007169178 0 # Node ID 705dcbf94639cc5fe6438a177e77649e111e5c27 # Parent 697fabe1453e10eb90ff6ad5dce83f604f82b09a Sound_DecodeAll() is now more robust. diff -r 697fabe1453e -r 705dcbf94639 SDL_sound.c --- 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);