[MPlayer-cvslog] r38340 - trunk/libmpdemux/mf.c

al subversion at mplayerhq.hu
Thu Feb 24 18:35:18 EET 2022


Author: al
Date: Thu Feb 24 18:35:18 2022
New Revision: 38340

Log:
libmpdemux/mf: Replace sprintf by mp_asprintf

It's not a good idea to use sprintf. Especially in this case where
the format string is supplied by the user.

Modified:
   trunk/libmpdemux/mf.c

Modified: trunk/libmpdemux/mf.c
==============================================================================
--- trunk/libmpdemux/mf.c	Thu Feb 24 18:21:17 2022	(r38339)
+++ trunk/libmpdemux/mf.c	Thu Feb 24 18:35:18 2022	(r38340)
@@ -37,6 +37,7 @@
 #include "mp_msg.h"
 #include "help_mp.h"
 #include "stream/stream.h"
+#include "mp_strings.h"
 
 #include "mf.h"
 
@@ -110,10 +111,10 @@ mf_t* open_mf(char * filename){
    goto exit_mf;
   }
 
- fname=malloc( strlen( filename ) + 32 );
-
  if ( !strchr( filename,'%' ) )
   {
+   fname=malloc( strlen( filename ) + 32 );
+
    strcpy( fname,filename );
    if ( !strchr( filename,'*' ) ) strcat( fname,"*" );
 
@@ -142,19 +143,23 @@ mf_t* open_mf(char * filename){
 
  while ( error_count < 5 )
   {
-   sprintf( fname,filename,count++ );
+   fname = mp_asprintf( filename,count++ );
+
    if ( stat( fname,&fs ) )
     {
      error_count++;
      mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
+     free(fname);
     }
     else
     {
      mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
-     mf->names[mf->nr_of_files]=strdup( fname );
+     mf->names[mf->nr_of_files]=fname;
 //     mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] );
      mf->nr_of_files++;
     }
+
+   fname = NULL;
   }
 
  mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );


More information about the MPlayer-cvslog mailing list