Mercurial > mplayer.hg
changeset 3798:d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
author | iive |
---|---|
date | Thu, 27 Dec 2001 18:38:10 +0000 |
parents | 266f47fd6e75 |
children | f41bbaebcea3 |
files | codec-cfg.c codec-cfg.h |
diffstat | 2 files changed, 31 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/codec-cfg.c Thu Dec 27 18:37:19 2001 +0000 +++ b/codec-cfg.c Thu Dec 27 18:38:10 2001 +0000 @@ -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;
--- a/codec-cfg.h Thu Dec 27 18:37:19 2001 +0000 +++ b/codec-cfg.h Thu Dec 27 18:38:10 2001 +0000 @@ -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);