# HG changeset patch # User Ryan C. Gordon # Date 1015787086 0 # Node ID e1429f96adedf12535b7e1d13c9e40a4b1aecb6b # Parent 0ac181b5adc68337f3ce6be1f0cd87cace8b02c1 Replaced exit() calls with proper error reporting. diff -r 0ac181b5adc6 -r e1429f96aded decoders/mpglib/common.c --- a/decoders/mpglib/common.c Sun Mar 10 19:03:56 2002 +0000 +++ b/decoders/mpglib/common.c Sun Mar 10 19:04:46 2002 +0000 @@ -6,6 +6,11 @@ #include #include +#include "SDL_sound.h" + +#define __SDL_SOUND_INTERNAL__ +#include "SDL_sound_internal.h" + #include "mpg123_sdlsound.h" struct parameter param = { 1 , 1 , 0 , 0 }; @@ -65,8 +70,8 @@ fr->lay = 4-((newhead>>17)&3); if( ((newhead>>10)&0x3) == 0x3) { - fprintf(stderr,"Stream error\n"); - exit(1); + Sound_SetError("MPGLIB: Corrupted header"); + return 0; } if(fr->mpeg25) { fr->sampling_frequency = 6 + ((newhead>>10)&0x3); diff -r 0ac181b5adc6 -r e1429f96aded decoders/mpglib/interface.c --- a/decoders/mpglib/interface.c Sun Mar 10 19:03:56 2002 +0000 +++ b/decoders/mpglib/interface.c Sun Mar 10 19:04:46 2002 +0000 @@ -2,6 +2,11 @@ #include #include +#include "SDL_sound.h" + +#define __SDL_SOUND_INTERNAL__ +#include "SDL_sound_internal.h" + #include "mpg123_sdlsound.h" #include "mpglib_sdlsound.h" @@ -95,10 +100,8 @@ } -static int read_buf_byte(struct mpstr *mp) +static int read_buf_byte(struct mpstr *mp, unsigned long *retval) { - unsigned int b; - int pos; pos = mp->tail->pos; @@ -106,32 +109,48 @@ remove_buf(mp); pos = mp->tail->pos; if(!mp->tail) { - fprintf(stderr,"Fatal error!\n"); - exit(1); + Sound_SetError("MPGLIB: Fatal error! Short read in read_buf_byte()!"); + return 0; } } - b = mp->tail->pnt[pos]; + if (retval != NULL) + *retval = mp->tail->pnt[pos]; + mp->bsize--; mp->tail->pos++; - - return b; + return 1; } -static void read_head(struct mpstr *mp) +static int read_head(struct mpstr *mp) { + unsigned long val; unsigned long head; - head = read_buf_byte(mp); - head <<= 8; - head |= read_buf_byte(mp); + if (!read_buf_byte(mp, &val)) + return 0; + + head = val << 8; + + if (!read_buf_byte(mp, &val)) + return 0; + + head |= val; head <<= 8; - head |= read_buf_byte(mp); + + if (!read_buf_byte(mp, &val)) + return 0; + + head |= val; head <<= 8; - head |= read_buf_byte(mp); + + if (!read_buf_byte(mp, &val)) + return 0; + head |= val; mp->header = head; + return 1; } int decodeMP3(struct mpstr *mp,char *in,int isize,char *out, @@ -157,8 +176,13 @@ if(mp->bsize < 4) { return MP3_NEED_MORE; } - read_head(mp); - decode_header(&mp->fr,mp->header); + + if (!read_head(mp)) + return MP3_ERR; + + if (!decode_header(&mp->fr,mp->header)) + return MP3_ERR; + mp->framesize = mp->fr.framesize; }