<<< Date Index >>>     <<< Thread Index >>>

Re: [PATCH] Use NULL in vararg



[ last try to get through to the list ]

* Werner Koch wrote on Mon, Nov 08, 2004 at 09:25:55PM CET:
> On Mon, 8 Nov 2004 17:04:58 +0100, Ralf Wildenhues said:
> 
> >     snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
> > -   snprintf (buf, buflen, fmt, Context ? Context->pattern : 0);
> > +   snprintf (buf, buflen, fmt, Context ? Context->pattern : NULL);
> 
> Assuming a prefix of "%s", NULL is not a good idea because %s is not
> guaranteed to print something like "(null)" as glibc does.  Some libcs
> will simply segv here.  The proper way (if semantically okay) is to
> use 
> 
>       snprintf (buf, buflen, fmt, Context ? Context->pattern : "(null)");

Yes of course.  Thanks everybody for noticing that I did not think
before writing.

BTW, sorry for responding so late, but the ML spam filter seems to have
eaten some earlier message(s) of mine.

Regards,
Ralf

--- status.c    11 Dec 2002 11:19:40 -0000      3.1
+++ status.c    15 Nov 2004 12:33:29 -0000
@@ -266,7 +266,7 @@
       if (!optional)
       {
        snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
-       snprintf (buf, buflen, fmt, Context ? Context->pattern : 0);
+       snprintf (buf, buflen, fmt, Context ? Context->pattern : "(null)");
       }
       else if (!Context || !Context->pattern)
        optional = 0;