[MPlayer-dev-eng] [PATCH] some small updates
adland
adland123 at yahoo.com
Sat Mar 19 05:45:51 CET 2005
I am enclosing a set of small possible updates in this PATCH
please review
vidix/drivers/cyberblade_vid.c - missing FMT "%s"
vidix/drivers/unichrome_vid.c - missing FMT "%s"
postproc/swscale-example.c -dead unused function (we also have mp_msg already)
libmpdemux/mf.c - cast void ptr from mem alloc, check return values for error
put bounds on strcpy,sprintf (use n functions)
libdha/mtrr.c - put bounds on sprintf, use FMT for fprintf
libao2/ao_esd.c - replace printf with mp_msg
thank you
--- main/vidix/drivers/cyberblade_vid.c 2004-10-17 14:07:27.000000000 -0400
+++ updated/vidix/drivers/cyberblade_vid.c 2005-03-18 17:55:38.000000000 -0500
@@ -59,7 +59,7 @@
#ifdef DEBUG_LOGFILE
FILE *logfile=0;
-#define LOGWRITE(x) {if(logfile) fprintf(logfile,x);}
+#define LOGWRITE(x) {if(logfile) fprintf(logfile,"%s",x);}
#else
#define LOGWRITE(x)
#endif
--- main/vidix/drivers/unichrome_vid.c 2004-11-09 07:56:22.000000000 -0500
+++ updated/vidix/drivers/unichrome_vid.c 2005-03-18 17:56:05.000000000 -0500
@@ -83,7 +83,7 @@
#ifdef DEBUG_LOGFILE
FILE *logfile = 0;
-#define LOGWRITE(x) {if(logfile) fprintf(logfile,x);}
+#define LOGWRITE(x) {if(logfile) fprintf(logfile,"%s",x);}
#else
#define LOGWRITE(x)
#endif
--- main/postproc/swscale-example.c 2004-10-21 16:59:53.000000000 -0400
+++ updated/postproc/swscale-example.c 2005-03-18 22:19:54.000000000 -0500
@@ -139,13 +139,6 @@
}
}
-void mp_msg_c( int x, const char *format, ... ){
- va_list va;
- va_start(va, format);
- vfprintf(stderr, format, va);
- va_end(va);
-}
-
void fast_memcpy(void *a, void *b, int s){ //FIXME
memcpy(a, b, s);
}
--- main/libmpdemux/mf.c 2003-04-25 06:20:15.000000000 -0400
+++ updated/libmpdemux/mf.c 2005-03-18 22:38:21.000000000 -0500
@@ -38,11 +38,20 @@
int error_count = 0;
int count = 0;
- mf=calloc( 1,sizeof( mf_t ) );
+ mf= (mf_t *) calloc( 1,sizeof( mf_t ) );
+ if (mf == NULL) {
+ mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] memory allocation failed\n");
+ goto exit_mf;
+ }
if( strchr( filename,',') )
{
- fname=malloc( 255 );
+ fname=(char *)malloc( 255*sizeof(char) );
+ if (fname==NULL) {
+ mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] memory allocation failed\n");
+ goto exit_mf;
+ }
+
mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] filelist: %s\n",filename );
while ( ( fname=strsep( &filename,"," ) ) )
@@ -53,8 +62,17 @@
}
else
{
- mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* )
);
+ mf->names=(char **)realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof(
char* ) );
+ if (mf->names == NULL) {
+ mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] memory reallocation failed\n");
+ goto exit_mf;
+ }
mf->names[mf->nr_of_files]=strdup( fname );
+ if (mf->names[mf->nr_of_files]==NULL) {
+ mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] memory allocation failed in strdup\
n");
+ goto exit_mf;
+ }
+
// mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_file
s,mf->names[mf->nr_of_files] );
mf->nr_of_files++;
}
@@ -64,12 +82,16 @@
goto exit_mf;
}
- fname=malloc( strlen( filename ) + 32 );
+ fname=(char *)malloc( (strlen( filename ) + 32)*sizeof(char) );
+ if (fname==NULL) {
+ mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] memory allocation failed\n");
+ goto exit_mf;
+ }
if ( !strchr( filename,'%' ) )
{
- strcpy( fname,filename );
- if ( !strchr( filename,'*' ) ) strcat( fname,"*" );
+ strncpy( fname,filename,strlen(filename) );
+ if ( !strchr( filename,'*' ) ) strncat( fname,"*",1 );
mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",fname );
@@ -77,8 +99,11 @@
{ free( mf ); free( fname ); return NULL; }
mf->nr_of_files=gg.gl_pathc;
- mf->names=malloc( gg.gl_pathc * sizeof( char* ) );
-
+ mf->names=(char **) malloc( gg.gl_pathc * sizeof( char* ) );
+ if (mf->names==NULL){
+ mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] memory allocation failed\n");
+ goto exit_mf;
+ }
mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d (%d)\n",mf->nr_of_f
iles, gg.gl_pathc * sizeof( char* ) );
for( i=0;i < gg.gl_pathc;i++ )
@@ -86,6 +111,11 @@
stat( gg.gl_pathv[i],&fs );
if( S_ISDIR( fs.st_mode ) ) continue;
mf->names[i]=strdup( gg.gl_pathv[i] );
+ if (mf->names[i]==NULL) {
+ mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] memory allocation failed in strdup\
n");
+ goto exit_mf;
+ }
+
// mp_msg( MSGT_STREAM,MSGL_DBG2,"[mf] added file %d.: %s\n",i,mf->names[i
] );
}
globfree( &gg );
@@ -96,7 +126,7 @@
while ( error_count < 5 )
{
- sprintf( fname,filename,count++ );
+ snprintf( fname,strlen(filename)+30,"%s%d",filename,count++ );
if ( stat( fname,&fs ) )
{
error_count++;
@@ -104,8 +134,17 @@
}
else
{
- mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
+ mf->names=(char **)realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( c
har* ) );
+ if (mf->names==NULL) {
+ mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] memory reallocation failed\n");
+ goto exit_mf;
+ }
mf->names[mf->nr_of_files]=strdup( fname );
+ if (mf->names[mf->nr_of_files]==NULL) {
+ mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] memory allocation failed in strdup\
n");
+ goto exit_mf;
+ }
+
// 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++;
}
@@ -114,7 +153,8 @@
mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
exit_mf:
- free( fname );
+ if (fname!=NULL)
+ free( fname );
return mf;
#else
mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] mf support is disabled on your os\n");
--- main/libdha/mtrr.c 2002-06-07 18:43:25.000000000 -0400
+++ updated/libdha/mtrr.c 2005-03-18 22:26:08.000000000 -0500
@@ -43,8 +43,8 @@
{
char sout[256];
unsigned wr_len;
- sprintf(sout,"base=0x%08X size=0x%08X type=%s\n",base,size,stype);
- wr_len = fprintf(mtrr_fd,sout);
+ snprintf(sout,255,"base=0x%08X size=0x%08X type=%s\n",base,size,stype);
+ wr_len = fprintf(mtrr_fd,"%s",sout);
/*printf("MTRR: %s\n",sout);*/
fclose(mtrr_fd);
return wr_len == strlen(sout) ? 0 : EPERM;
--- main/libao2/ao_esd.c 2005-01-13 09:32:31.000000000 -0500
+++ updated/libao2/ao_esd.c 2005-03-18 21:13:21.000000000 -0500
@@ -41,7 +41,7 @@
#undef ESD_DEBUG
#if ESD_DEBUG
-#define dprintf(...) printf(__VA_ARGS__)
+#define dprintf(...) mp_msg(MSGT_AO, MSGL_DBG2,__VA_ARGS__)
#else
#define dprintf(...) /**/
#endif
More information about the MPlayer-dev-eng
mailing list