From e0c43586aeb65490438ba2aca7bdc2a0ecf7f5e0 Mon Sep 17 00:00:00 2001 From: pl Date: Wed, 19 Dec 2001 13:03:22 +0000 Subject: [PATCH] x = malloc(strlen(s) + c) ... strcpy(x, s) replaced by x = strdup(s) Note: sometimes c was 0 and that was a bug Note2: code still has to be added to check the returned value of these funcs git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3613 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/demux_viv.c | 12 ++++-------- libmpdemux/tv.c | 3 +-- libmpdemux/url.c | 6 ++---- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/libmpdemux/demux_viv.c b/libmpdemux/demux_viv.c index 891925d9c6..a9611d2898 100644 --- a/libmpdemux/demux_viv.c +++ b/libmpdemux/demux_viv.c @@ -191,26 +191,22 @@ static void vivo_parse_text_header(demuxer_t *demux, int header_len) if (!strcmp(opt, "Title")) { demux_info_add(demux, "name", param); - priv->title = malloc(strlen(param)); - strcpy(priv->title, param); + priv->title = strdup(param); } if (!strcmp(opt, "Author")) { demux_info_add(demux, "author", param); - priv->author = malloc(strlen(param)); - strcpy(priv->author, param); + priv->author = strdup(param); } if (!strcmp(opt, "Copyright")) { demux_info_add(demux, "copyright", param); - priv->copyright = malloc(strlen(param)); - strcpy(priv->copyright, param); + priv->copyright = strdup(param); } if (!strcmp(opt, "Producer")) { demux_info_add(demux, "encoder", param); - priv->producer = malloc(strlen(param)); - strcpy(priv->producer, param); + priv->producer = strdup(param); } /* get next token */ diff --git a/libmpdemux/tv.c b/libmpdemux/tv.c index cc9271c334..c01fd5ca47 100644 --- a/libmpdemux/tv.c +++ b/libmpdemux/tv.c @@ -343,8 +343,7 @@ int tv_init(tvi_handle_t *tvh) mp_msg(MSGT_TV, MSGL_INFO, " comment: %s\n", tvh->info->comment); params = malloc(sizeof(tvi_param_t)*2); - params[0].opt = malloc(strlen("input")); - sprintf((char *)params[0].opt, "input"); + params[0].opt = strdup("input"); params[0].value = malloc(sizeof(int)); (int)*(void **)params[0].value = tv_param_input; params[1].opt = params[1].value = NULL; diff --git a/libmpdemux/url.c b/libmpdemux/url.c index 8633133319..b73a51fe44 100644 --- a/libmpdemux/url.c +++ b/libmpdemux/url.c @@ -29,12 +29,11 @@ url_new(char* url) { memset( Curl, 0, sizeof(URL_t) ); // Copy the url in the URL container - Curl->url = (char*)malloc(strlen(url)+1); + Curl->url = strdup(url); if( Curl->url==NULL ) { printf("Memory allocation failed!\n"); return NULL; } - strcpy(Curl->url, url); // extract the protocol ptr1 = strstr(url, "://"); @@ -86,12 +85,11 @@ url_new(char* url) { // check if it's not a trailing '/' if( strlen(ptr2)>1 ) { // copy the path/filename in the URL container - Curl->file = (char*)malloc(strlen(ptr2)+1); + Curl->file = strdup(ptr2); if( Curl->file==NULL ) { printf("Memory allocation failed!\n"); return NULL; } - strcpy(Curl->file, ptr2); } } // Check if a filenme was given or set, else set it with '/'