Lost last character in messages(init.c)

Denys Vlasenko vda.linux at googlemail.com
Wed Dec 10 11:46:08 UTC 2008


On Wednesday 10 December 2008 10:10, walter harms wrote:
> > diff -urN busybox-1.13.0.old/init/init.c busybox-1.13.0.new/init/init.c
> > --- busybox-1.13.0.old/init/init.c      2008-12-09 20:30:31.000000000 +0300
> > +++ busybox-1.13.0.new/init/init.c      2008-12-09 20:20:22.000000000 +0300
> > @@ -118,7 +118,7 @@
> > 
> >        msg[0] = '\r';
> >        va_start(arguments, fmt);
> > -       l = vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments);
> > +       l = vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments) + 1;
> 
> 
> >        if (l > sizeof(msg) - 2)
> >                l = sizeof(msg) - 2;
> >        msg[l] = '\0';
> 
> can we replace it just with:  ?
>    msg[sizeof(msg) - 2] = '\0';
> 
> if l>=(sizeof(msg) - 2) it will guarantee a terminating 0, else we set it twice what is harmless as snprintf
> will terminate with 0.

l is needed later
--
vda



More information about the busybox mailing list