NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/39135: /usr/bin/awk: printf supports extra- (and broken) formatting rules
The following reply was made to PR bin/39135; it has been noted by GNATS.
From: "Greg A. Woods; Planix, Inc." <woods%planix.ca@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: bin/39135: /usr/bin/awk: printf supports extra- (and broken)
formatting rules
Date: Sun, 13 Jul 2008 13:03:17 -0400
On 12-Jul-08, at 1:30 PM, David Laight wrote:
>
> On Sat, Jul 12, 2008 at 04:00:06PM +0000, Greg A. Woods; Planix,
> Inc. wrote:
>> The following reply was made to PR bin/39135; it has been noted by
>> GNATS.
>>
>> From: "Greg A. Woods; Planix, Inc." <woods%planix.ca@localhost>
>> To: gnats-bugs%NetBSD.org@localhost
>> Cc:
>> Subject: Re: bin/39135: /usr/bin/awk: printf supports extra- (and
>> broken) formatting rules
>> Date: Sat, 12 Jul 2008 11:58:12 -0400
>>
>> On 11-Jul-08, at 8:35 PM, cheusov%tut.by@localhost wrote:
>>
>>> awk 'BEGIN {printf "%llu\n", 123}'
>>
>>
>> Hah! Interesting side effect of directly using printf(3)! ;-)
>
> So using %n will have interesting effects ...
Not so much. I goofed in remembering how much of the formatting was
handed off to libc. It's actually sprintf(3) that's used to format
numbers, and only after all the '%' syntax in the format string has
(supposedly) been decoded for the most part. "%n" isn't directly
supported. See run.c:format() and the following example.
$ awk 'BEGIN {printf "%n\n", 123}'
awk: weird printf conversion %n
source line number 1
%n123
I'm still not sure what exactly is wrong with AWK's use of sprintf()
-- on first glance I would have thought that the "long long" flag
should already be ignored, though on closer examination it seems any
number of length flags will be skipped over _and_ preserved and passed
to sprintf():
$ awk 'BEGIN {printf "%llllld\n", 123}'
578115701986820219
$ awk 'BEGIN {printf "%#0lllllx\n", 123}'
0x805e12b0000007b
Perhaps the code from printf(1) [which seems to get this stuff right]
could be enhanced to match AWK's requirements and then be used to
replace the existing format() function.
On the other hand fixing the isalfpha() && != 'l' && != 'h' && != 'L'
test to be much more stringent (in the manner of how printf(1) does
it) would perhaps be the least intrusive fix.
--
Greg A. Woods; Planix, Inc.
<woods%planix.ca@localhost>
Home |
Main Index |
Thread Index |
Old Index