[Mplayer-cvslog] CVS: main codec-cfg.c,1.55,1.56 codec-cfg.h,1.30,1.31

Ivan Kalvachev iive at mplayer.dev.hu
Thu Dec 27 19:38:13 CET 2001


Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv5741

Modified Files:
	codec-cfg.c codec-cfg.h 
Log Message:
fixed few segfaults, make parse_codec_cfg() return int

Index: codec-cfg.c
===================================================================
RCS file: /cvsroot/mplayer/main/codec-cfg.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- codec-cfg.c	27 Dec 2001 05:09:42 -0000	1.55
+++ codec-cfg.c	27 Dec 2001 18:38:10 -0000	1.56
@@ -6,6 +6,9 @@
 
 #define DEBUG
 
+//disable asserts
+#define NDEBUG 
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
@@ -399,6 +402,7 @@
 out_ok:
 	return i;
 out_eof:
+	read_nextline = 1;
 	return RET_EOF;
 out_eol:
 	return RET_EOL;
@@ -409,30 +413,37 @@
 static int nr_vcodecs = 0;
 static int nr_acodecs = 0;
 
-codecs_t **parse_codec_cfg(char *cfgfile)
+int parse_codec_cfg(char *cfgfile)
 {
 	codecs_t *codec = NULL; // current codec
 	codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs
-	static codecs_t *ret_codecs[2] = {NULL,NULL};
 	char *endptr;	// strtoul()...
 	int *nr_codecsp;
 	int codec_type;		/* TYPE_VIDEO/TYPE_AUDIO */
 	int tmp, i;
+	
+	// in case we call it secont time
+	if(video_codecs!=NULL)free(video_codecs);
+	else video_codecs=NULL;
+ 
+ 	if(audio_codecs!=NULL)free(audio_codecs);
+	else audio_codecs=NULL;
+	
+	nr_vcodecs = 0;
+	nr_acodecs = 0;
 
-#ifdef DEBUG
-	assert(cfgfile != NULL);
-#endif
-
+	if(cfgfile==NULL)return 0; 
+	
 	printf("Reading %s: ", cfgfile);
 
 	if ((fp = fopen(cfgfile, "r")) == NULL) {
 		printf("can't open '%s': %s\n", cfgfile, strerror(errno));
-		return NULL;
+		return 0;
 	}
 
 	if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) {
 		printf("can't get memory for 'line': %s\n", strerror(errno));
-		return NULL;
+		return 0;
 	}
 
 	/*
@@ -483,7 +494,8 @@
 			if (get_token(1, 1) < 0)
 				goto err_out_parse_error;
 			for (i = 0; i < *nr_codecsp - 1; i++) {
-				if (!strcmp(token[0], (*codecsp)[i].name)) {
+				if(( (*codecsp)[i].name!=NULL) && 
+				    (!strcmp(token[0], (*codecsp)[i].name)) ) {
 					printf("codec name '%s' isn't unique", token[0]);
 					goto err_out_print_linenum;
 				}
@@ -592,12 +604,12 @@
 	printf("%d audio & %d video codecs\n", nr_acodecs, nr_vcodecs);
 	if(video_codecs) video_codecs[nr_vcodecs].name = NULL;
 	if(audio_codecs) audio_codecs[nr_acodecs].name = NULL;
-	ret_codecs[0] = video_codecs;
-	ret_codecs[1] = audio_codecs;
 out:
 	free(line);
+	line=NULL;
 	fclose(fp);
-	return ret_codecs;
+	return 1;
+
 err_out_parse_error:
 	printf("parse error");
 err_out_print_linenum:
@@ -607,9 +619,13 @@
 		free(audio_codecs);
 	if (video_codecs)
 		free(video_codecs);
+	video_codecs=NULL;
+	audio_codecs=NULL;
+
 	free(line);
-	free(fp);
-	return NULL;
+	line=NULL;
+	fclose(fp);
+	return 0;
 err_out_not_valid:
 	printf("codec is not defined correctly");
 	goto err_out_print_linenum;

Index: codec-cfg.h
===================================================================
RCS file: /cvsroot/mplayer/main/codec-cfg.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- codec-cfg.h	27 Dec 2001 05:09:42 -0000	1.30
+++ codec-cfg.h	27 Dec 2001 18:38:10 -0000	1.31
@@ -78,7 +78,7 @@
   short priority;
 } codecs_t;
 
-codecs_t** parse_codec_cfg(char *cfgfile);
+int parse_codec_cfg(char *cfgfile);
 codecs_t* find_video_codec(unsigned int fourcc, unsigned int *fourccmap, codecs_t *start);
 codecs_t* find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, codecs_t *start);
 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,codecs_t *start,int audioflag);




More information about the MPlayer-cvslog mailing list