[MPlayer-dev-eng] [PATCH 2/4] String handling audit/cleanup

Nicholas Kain njkain at gmail.com
Sat Mar 3 17:10:20 CET 2007


On 3/3/07, Nico Sabbi <nicola_sabbi at fastwebnet.it> wrote:
> > @@ -868,7 +869,7 @@ static int open_s(stream_t *stream,int m
> >          int i;
> >          char buf[33];
> >          for (i = 0; i < 16; i ++)
> > -          sprintf(buf+2*i, "%02X", discid[i]);
> > +          snprintf(buf+2*i, sizeof buf - ((buf+2*i)-buf), "%02X",
> > discid[i]);
> >          mp_msg(MSGT_IDENTIFY, MSGL_V, "ID_DVD_DISC_ID=%s\n", buf);
> >        }
> >      }
> >
> > looks too horrendous to read (not that stream_dvd.c looks nice overall,
> > very old-team style)

Agreed.  The attached patch is much clearer.
-------------- next part --------------
--- stream/stream_dvd.c.orig	2007-03-03 11:02:44.000000000 -0500
+++ stream/stream_dvd.c	2007-03-03 11:05:57.000000000 -0500
@@ -867,9 +867,11 @@ static int open_s(stream_t *stream,int m
       if (DVDDiscID(dvd, discid) >= 0)
       {
         int i;
-        char buf[33];
-        for (i = 0; i < 16; i ++)
-          sprintf(buf+2*i, "%02X", discid[i]);
+        char buf[33], tmp[4];
+        for (i = 0; i < 16; i ++) {
+          snprintf(tmp, sizeof(tmp), "%02X", discid[i]);
+          strlcat(buf, tmp, sizeof(buf));
+        }
         mp_msg(MSGT_IDENTIFY, MSGL_V, "ID_DVD_DISC_ID=%s\n", buf);
       }
     }


More information about the MPlayer-dev-eng mailing list