Subject: bin/7834: gawk-3.0.3's bug about OFMT
To: None <gnats-bugs@gnats.netbsd.org>
From: NAKAJIMA Yoshihiro <nakayosh@kcn.ne.jp>
List: netbsd-bugs
Date: 06/22/1999 09:50:52
>Number: 7834
>Category: bin
>Synopsis: gawk-3.0.3's bug about OFMT
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jun 22 09:50:01 1999
>Last-Modified:
>Originator: NAKAJIMA Yoshihiro
>Organization:
>Release: NetBSD-current 1999/06/21
>Environment:
System: NetBSD asura 1.4D NetBSD 1.4D (ASURA) #0: Tue Jun 22 21:15:43 JST 1999 nakayosh@asura:/usr/src/sys/arch/i386/compile/ASURA i386
>Description:
Gawk-3.0.3 recently imported to -current has a bug about OFMT.
It fails expiration of Cnews (Cleanup Release of C News, with patch
CR.G).
This bug has been fixed in recent BETA Release of gawk.
>How-To-Repeat:
Executing this script
-------- cut here --------
% cat test.awk
BEGIN {
OFMT = "%.8g" # NG
# OFMT = "%.6g" # OK
# OFMT = "%.4g" # NG
lowest = 99999999
}
/^[0-9]+$/ {
if ($1 < lowest)
lowest = $1
}
/:$/ {
if (dir != "")
print dir, lowest
dir = $0
lowest = 99999999
}
-------- cut here --------
with these data
-------- cut here --------
% cat test.data
foo:
1040
1025
bar:
72
78
baz:
1763
qux:
:
-------- cut here --------
Awk bundled with NetBSD/i386 1.4 works well.
: % awk.old -f test.awk test.data
: foo: 1025
: bar: 72
: baz: 1763
: qux: 99999999
But new gawk doesn't in my environment.
: % awk.new -f test.awk test.data
: foo: 1025
: 72 72
: 1 1
: 1 1
>Fix:
The following patch is stolen from gawk-3.0.46.
diff -u src/gnu/dist/gawk/builtin.c.ORIG src/gnu/dist/gawk/builtin.c
--- src/gnu/dist/gawk/builtin.c.ORIG Mon Jun 14 05:39:15 1999
+++ src/gnu/dist/gawk/builtin.c Wed Jun 23 01:08:46 1999
@@ -1082,6 +1082,7 @@
register FILE *fp;
int numnodes, i;
NODE *save;
+ NODE *tval;
if (tree->rnode) {
int errflg; /* not used, sigh */
@@ -1118,8 +1119,11 @@
if (t[i]->flags & NUMBER) {
if (OFMTidx == CONVFMTidx)
(void) force_string(t[i]);
- else
- t[i] = format_val(OFMT, OFMTidx, t[i]);
+ else {
+ tval = tmp_number(t[i]->numbr);
+ unref(t[i]);
+ t[i] = format_val(OFMT, OFMTidx, tval);
+ }
}
}
>Audit-Trail:
>Unformatted: