Skip to content

Commit

Permalink
Sound_DecodeAll() is now more robust.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Dec 1, 2001
1 parent ea55e9b commit 076979e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions SDL_sound.c
Expand Up @@ -638,32 +638,35 @@ Uint32 Sound_DecodeAll(Sound_Sample *sample)
{
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;
Sound_SetError(ERR_OUT_OF_MEMORY);
} /* 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);

Expand Down

0 comments on commit 076979e

Please sign in to comment.