Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: Slightly improve printf %s



On Mon, Aug 08, 2005 at 08:21:28PM +0200, Thorsten Dahlheimer wrote:
> After I made this change, the test suite uncovered a bug (which I
> introduced) in the handling of %b (and now %s) when no argument is
> left, so the patch includes a fix for that, too.

I didn't see that fix in the patch.  I assume you're talking about
this line (which is executed when the arg is missing):

        count += fprintf(fout, "%*c", width, ' ');

... since that would output a single space, even when "width" is 0.  I
changed the "else" that is in front of that line to "else if (width)",
and it fixes the problem (I could have also changed the line to use
fprintf(fout, "%*s", width, ""), but the former seems a litle more
optimal).

As for the change to how %s is handled, can you show me an example where
this is needed?  In my simple tests, if a variable has a literal null in
it, using either %b or %s to print it out with printf truncates the
variable at the null (and, of course, a backslash-zero can be passed to
%b to get a real null, but %s doesn't evaluate backslashes).

..wayne..



Messages sorted by: Reverse Date, Date, Thread, Author