changeset 273:e1429f96aded

Replaced exit() calls with proper error reporting.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 10 Mar 2002 19:04:46 +0000
parents 0ac181b5adc6
children 9e7f9e09ea0e
files decoders/mpglib/common.c decoders/mpglib/interface.c
diffstat 2 files changed, 47 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- 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 <sys/stat.h>
 #include <fcntl.h>
 
+#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);
--- 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 <stdlib.h>
 #include <stdio.h>
 
+#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;
 	}