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

Rich Felker dalias at aerifal.cx
Fri Mar 2 22:59:11 CET 2007


On Fri, Mar 02, 2007 at 10:48:21PM +0100, Nico Sabbi wrote:
> Nicholas Kain wrote:
> >Patches for the stream subdirectory.  Note that all of my patches
> >correctly apply from the root directory.
> 
> notice: I manually quoted the patch

FYI: if you go to the attachments view in mutt, pressing ^E lets you
temporarily "change the type" of an attachment. Then they'll
subsequently show up inline until you reload the mail folder.

> >--- stream/stream_dvb.c.orig    2007-03-02 11:18:16.000000000 -0500
> >+++ stream/stream_dvb.c 2007-03-02 13:42:36.000000000 -0500
> >@@ -176,8 +176,7 @@ static dvb_channels_list *dvb_get_channe
> >                        ptr->name = (char*) malloc(k+1);
> >                        if(! ptr->name)
> >                                continue;
> >-                       strncpy(ptr->name, line, k);
> >-                       ptr->name[k] = 0;
> >+                       strlcpy(ptr->name, line, k+1);
> 
> it's shorter, but to me it looks equivalent

It's more legible and avoids zero-filling the end of name. (strncpy
zero-fills up to the full length)

> >@@ -764,7 +763,7 @@ dvb_config_t *dvb_get_config(void)
> >        conf->cards = NULL;
> >        for(i=0; i<MAX_CARDS; i++)
> >        {
> >-               sprintf(filename, "/dev/dvb/adapter%d/frontend0", i);
> >+               snprintf(filename, sizeof
> >filename,"/dev/dvb/adapter%d/frontend0", i);
> >                fd = open(filename, O_RDONLY|O_NONBLOCK);
> 
> filename is allocated as char[30] and MAX_CARDS is defined as 4, so in 
> no way sprintf() can overflow

Sure, but no reason not to express that in the call.. On any sane
system sprintf is implemented in terms of snprintf anyway..

Rich



More information about the MPlayer-dev-eng mailing list