[MPlayer-dev-eng] [PATCH]printf format string used everywhere

Frédéric Marchal fmarchal at perso.be
Fri Oct 8 21:20:49 CEST 2010


On Thursday 07 October 2010 21:09:48 Reimar Döffinger wrote:
> On Wed, Sep 15, 2010 at 01:38:28PM +0200, Frédéric Marchal wrote:
> > Index: stream/librtsp/rtsp_rtp.c
> > -  snprintf (dest, len, parse1 + strlen (RTSP_SETUP_DESTINATION));
> > +  snprintf (dest, len, "%s", parse1 + strlen (RTSP_SETUP_DESTINATION));
> 
> av_strlcpy ?

There are four other instances of snprintf("%s") with three of them that
are probable candidates for the same change. Should I try to replace
those too ?

> 
> > Index: vidix/mtrr.c
> > ===================================================================
> > --- vidix/mtrr.c        (révision 32250)
> > +++ vidix/mtrr.c        (copie de travail)
> > @@ -57,7 +57,7 @@ int   mtrr_set_type(unsigned base,unsigned size,int
> > 
> >         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);
> > +       wr_len = fprintf(mtrr_fd,"%s",sout);
> > 
> >         /*printf("MTRR: %s\n",sout);*/
> >         fclose(mtrr_fd);
> >         return wr_len == strlen(sout) ? 0 : EPERM;
> 
> There isn't really any point in having that intermediate sout variable.

Then, the commented out printf now contains a duplicate copy of the same
format string but I guess it doesn't matter as it is commented out...

Here is the new patch.

---
Index: libmpcodecs/vd_ffmpeg.c
===================================================================
--- libmpcodecs/vd_ffmpeg.c	(revision 32451)
+++ libmpcodecs/vd_ffmpeg.c	(working copy)
@@ -227,7 +227,7 @@
 
     print_prefix= strchr(fmt, '\n') != NULL;
     vsnprintf(buf, sizeof(buf), fmt, vl);
-    mp_msg(type, mp_level, buf);
+    mp_msg(type, mp_level, "%s", buf);
 }
 
 static void set_format_params(struct AVCodecContext *avctx, enum PixelFormat fmt){
Index: stream/librtsp/rtsp_rtp.c
===================================================================
--- stream/librtsp/rtsp_rtp.c	(revision 32451)
+++ stream/librtsp/rtsp_rtp.c	(working copy)
@@ -218,7 +218,7 @@
   len = strlen (parse1) - strlen (parse2)
     - strlen (RTSP_SETUP_DESTINATION) + 1;
   dest = (char *) malloc (len + 1);
-  snprintf (dest, len, parse1 + strlen (RTSP_SETUP_DESTINATION));
+  av_strlcpy (dest, len, parse1 + strlen (RTSP_SETUP_DESTINATION));
   free (line_copy);
 
   return dest;
Index: vidix/mtrr.c
===================================================================
--- vidix/mtrr.c	(revision 32451)
+++ vidix/mtrr.c	(working copy)
@@ -54,13 +54,11 @@
     mtrr_fd = fopen("/proc/mtrr","wt");
     if(mtrr_fd)
     {
-	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);
-	/*printf("MTRR: %s\n",sout);*/
+	wr_len = fprintf(mtrr_fd,"base=0x%08X size=0x%08X type=%s\n",base,size,stype);
+	/*printf("MTRR: base=0x%08X size=0x%08X type=%s\n",base,size,stype);*/
 	fclose(mtrr_fd);
-	return wr_len == strlen(sout) ? 0 : EPERM;
+	return wr_len < 0 ? 0 : EPERM;
     }
     return ENOSYS;
 #elif defined (__i386__ ) && defined (__NetBSD__) && __NetBSD_Version__ > 105240000


More information about the MPlayer-dev-eng mailing list