bug-bash
[Top][All Lists]
Advanced

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

Re: bug#9129: Built-in printf Sits Awkwardly with UDP.


From: Chet Ramey
Subject: Re: bug#9129: Built-in printf Sits Awkwardly with UDP.
Date: Sun, 24 Jul 2011 20:54:51 -0400
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11

On 7/22/11 12:32 PM, Ralph Corderoy wrote:
> Hi Jim,
> 
>>> On 07/20/2011 07:34 AM, Ralph Corderoy wrote:
>>>> BTW, the code for the built-in printf has a bug.  For negative
>>>> field-widths it negates a negative integer without checking it
>>>> will fit.  E.g. on this 64-bit machine
>>>>
>>>>      $ printf '%-9223372036854775808s.\n' foo
>>>>      foo.
>>>>      $

Bash doesn't turn this into a negative integer.  It skips over it and
passes the entire business to printf(3), as Eric surmised.

> Just to ensure there's no confusion, as far as bash's built-in printf is
> concerned one aspect of it is about a negative field width since
> 
>     $ printf '.%*q.\n' -10 foo
>     .foo       .
> 
> is implemented by converting the "-10" into a number, spotting it's
> negative, setting the left-justified flag, and then negating the number.

As printf(3) and ISO C specify, by the way (Posix is silent on the `*'
field width specifier).  Bash simply clamps the result at INT_MIN, which
turns into a left-justified INT_MAX, and goes on.  The question is whether
it should turn an out-of-range field width into 0, an error, or
INT_{MIN,MAX}.  Jim Meyering is correct when he says it's unspecified.
Different implementations have gone different ways.

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



reply via email to

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