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