bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: small fix for lib/sh/snprintf.c


From: Chet Ramey
Subject: Re: small fix for lib/sh/snprintf.c
Date: Thu, 12 Apr 2012 20:27:01 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

On 4/12/12 12:25 PM, Petr Sumbera wrote:
> Hi,
> 
> we are running Bash 3.2.38 on Solaris 10 where asprintf() isn't available.
> Thus code in snprintf.c is used.
> 
> There is a problem with following command:
> 
> bash -c 'printf "x%10.0fx\n" 123'
> x0000000123x
> 
> Where correct output should be:
> x       123x
> 
> It seems that '0' after '.' enables zero padding. Please see proposed patch
> bellow:
> 
> --- bash-3.2.48/lib/sh/snprintf.c       Tue Dec 12 12:10:18 2006
> +++ bash-3.2.48/lib/sh/snprintf.c       Thu Apr 12 08:55:44 2012
> @@ -1277,6 +1277,8 @@
>                 data->flags |= PF_ALTFORM;
>                 continue;
>               case '0':
> +               if (data->flags & PF_DOT)
> +                 continue;
>                 data->flags |= PF_ZEROPAD;
>                 data->pad = '0';
>                 continue;
> 
> The same code seems to be also in Bash 4.1 so I guess the problem is still
> there.
> 
> Any comments?

Thanks for the report.  Try this slightly improved patch; yours (and the
original code) doesn't treat a precision specifier beginning with a `0'
correctly.  (And the test has to use `printf -v' to exercise the right
code in bash-4.0 and later.)

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

Attachment: snprintf-zeropad.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]