[MPlayer-dev-eng] Re: [PATCH] minor tweak to title range parsing

Robert Henney robh at rut.org
Sat Apr 8 00:12:41 CEST 2006


On Fri, Apr 07, 2006 at 03:10:43PM -0400, Rich Felker wrote:
> On Fri, Apr 07, 2006 at 01:27:37PM -0400, Robert Henney wrote:
> > -                  snprintf(entbuf,9,"dvd://%d",j);
> > +		  entbuf[sizeof entbuf - 1] = '\0';
> > +                  snprintf(entbuf,sizeof entbuf - 1,"dvd://%d",j);
> 
> This part nonsense. snprintf always null-terminates. Use:
> snprintf(entbuf,sizeof entbuf,"dvd://%d",j);

right you are.  I guess I wasn't being very trusting of the various
implementations of the C99 (if I'm remembering the right one) standard
functions.

new patch attached
-------------- next part --------------
Index: main/parser-mpcmd.c
===================================================================
RCS file: /cvsroot/mplayer/main/parser-mpcmd.c,v
retrieving revision 1.24
diff -u -r1.24 parser-mpcmd.c
--- main/parser-mpcmd.c	24 Jan 2006 11:34:24 -0000	1.24
+++ main/parser-mpcmd.c	7 Apr 2006 17:25:10 -0000
@@ -61,7 +61,7 @@
 {
   int i,j,start_title=-1,end_title=-1;
   char *opt,*splitpos=NULL;
-  char entbuf[10];
+  char entbuf[11];
   int no_more_opts = 0;
   int opt_exit = 0; // flag indicating whether mplayer should exit without playing anything
   play_tree_t *last_parent, *last_entry = NULL, *root;
@@ -221,13 +221,14 @@
                    end_title=strtol(splitpos+1,NULL,10);
                }
               
-               if (dvd_range(start_title) && dvd_range(end_title) && (start_title<end_title))      
+               if (dvd_range(start_title) && dvd_range(end_title) && (start_title<=end_title))      
                {
                  for (j=start_title;j<=end_title;j++)
                  {
                   if (j!=start_title) 
                       entry=play_tree_new();
-                  snprintf(entbuf,9,"dvd://%d",j);
+                  snprintf(entbuf,sizeof entbuf,"dvd://%d",j);
                   play_tree_add_file(entry,entbuf);
                   add_entry(&last_parent,&last_entry,entry);
 		  last_entry = entry;


More information about the MPlayer-dev-eng mailing list