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 [email protected] http://cnswww.cns.cwru.edu/~chet/