xref: /illumos-gate/usr/src/test/util-tests/tests/awk/gnu/getnr2tb.awk (revision 78801af7286cd73dbc996d470f789e75993cf15d)
1#From vp@dmat.uevora.pt Thu Jun 18 09:10 EDT 1998
2#Received: from mescaline.gnu.org (we-refuse-to-spy-on-our-users@mescaline.gnu.org [158.121.106.21]) by cssun.mathcs.emory.edu (8.7.5/8.6.9-940818.01cssun) with ESMTP id JAA23649 for <arnold@mathcs.emory.edu>; Thu, 18 Jun 1998 09:10:54 -0400 (EDT)
3#Received: from khromeleque.dmat.uevora.pt by mescaline.gnu.org (8.8.5/8.6.12GNU) with ESMTP id JAA21732 for <arnold@gnu.ai.mit.edu>; Thu, 18 Jun 1998 09:11:19 -0400
4#Received: from khromeleque.dmat.uevora.pt (vp@localhost [127.0.0.1])
5#	by khromeleque.dmat.uevora.pt (8.8.8/8.8.8/Debian/GNU) with ESMTP id OAA11817
6#	for <arnold@gnu.ai.mit.edu>; Thu, 18 Jun 1998 14:13:57 +0100
7#Message-Id: <199806181313.OAA11817@khromeleque.dmat.uevora.pt>
8#To: arnold@gnu.org
9#Subject: concatenation bug in gawk 3.0.3
10#Date: Thu, 18 Jun 1998 14:13:57 +0200
11#From: Vasco Pedro <vp@dmat.uevora.pt>
12#Content-Type: text
13#Content-Length: 2285
14#Status: RO
15#
16#Hi,
17#
18#The gawk program '{print NR " " 10/NR}' will print:
19#
20#1 10
21#5 5
22#3 3.33333
23#2 2.5
24#2 2
25#1 1.66667
26#
27#instead of the correct:
28#
29#1 10
30#2 5
31#3 3.33333
32#4 2.5
33#5 2
34#6 1.66667
35#
36#You'll notice, on the incorrect output, that the first column is
37#the first digit of the second.
38#
39#I think the problem comes from the way builtin variables are handled.
40#Since the items to be concatenated are processed in reverse order and
41#the return value of tree_eval(``NR'') is a pointer to the value part
42#of `NR_node', the `unref()' of `NR_node' due to its second occurrence
43#will leave a dangling pointer in `strlist'. The reason that it doesn't
44#reuse the freed space with objects of the same type. (Using Electric
45#Fence with EF_PROTECT_FREE set confirms that freed space is being
46#accessed.)
47#
48#The enclosed patch (hack would be a better word to describe it) is
49#all I could come up with. With it installed, things seem to work ok,
50#but I doubt this is the correct way to do it. (If I treated the
51#case for `Node_field_spec' as the I did others, `make check' would
52#fail in several places.)
53#
54#Regards,
55#vasco
56#
57#*** eval.c~	Tue May  6 21:39:55 1997
58#--- eval.c	Thu Jun 18 13:39:25 1998
59#***************
60#*** 685,697 ****
61#  		return func_call(tree->rnode, tree->lnode);
62#
63#  		/* unary operations */
64#  	case Node_NR:
65#  	case Node_FNR:
66#  	case Node_NF:
67#  	case Node_FIELDWIDTHS:
68#  	case Node_FS:
69#  	case Node_RS:
70#- 	case Node_field_spec:
71#  	case Node_subscript:
72#  	case Node_IGNORECASE:
73#  	case Node_OFS:
74#--- 685,700 ----
75#  		return func_call(tree->rnode, tree->lnode);
76#
77#  		/* unary operations */
78#+ 	case Node_field_spec:
79#+ 		lhs = get_lhs(tree, (Func_ptr *) NULL);
80#+ 		return *lhs;
81#+
82#  	case Node_NR:
83#  	case Node_FNR:
84#  	case Node_NF:
85#  	case Node_FIELDWIDTHS:
86#  	case Node_FS:
87#  	case Node_RS:
88#  	case Node_subscript:
89#  	case Node_IGNORECASE:
90#  	case Node_OFS:
91#***************
92#*** 699,705 ****
93#  	case Node_OFMT:
94#  	case Node_CONVFMT:
95#  		lhs = get_lhs(tree, (Func_ptr *) NULL);
96#! 		return *lhs;
97#
98#  	case Node_var_array:
99#  		fatal("attempt to use array `%s' in a scalar context",
100#--- 702,710 ----
101#  	case Node_OFMT:
102#  	case Node_CONVFMT:
103#  		lhs = get_lhs(tree, (Func_ptr *) NULL);
104#! 		r = dupnode(*lhs);
105#! 		r->flags |= TEMP;
106#! 		return r;
107#
108#  	case Node_var_array:
109#  		fatal("attempt to use array `%s' in a scalar context",
110#
111{ print NR " " 10/NR }
112