1*e6d6c189SCody Peter Mello# Date: Mon, 27 Feb 2006 12:35:30 +0900 2*e6d6c189SCody Peter Mello# From: KIMURA Koichi <kimura.koichi@canon.co.jp> 3*e6d6c189SCody Peter Mello# Subject: gawk: sub_common has multi-byte aware bug 4*e6d6c189SCody Peter Mello# To: bug-gawk@gnu.org 5*e6d6c189SCody Peter Mello# Message-id: <20060227121045.2198.KIMURA.KOICHI@canon.co.jp> 6*e6d6c189SCody Peter Mello# 7*e6d6c189SCody Peter Mello# Hi, 8*e6d6c189SCody Peter Mello# 9*e6d6c189SCody Peter Mello# A certain user faced bug of sub builtin function and report to me. 10*e6d6c189SCody Peter Mello# Then I investigated the bug. 11*e6d6c189SCody Peter Mello# 12*e6d6c189SCody Peter Mello# reproduce script is here. 13*e6d6c189SCody Peter Mello 14*e6d6c189SCody Peter MelloBEGIN { 15*e6d6c189SCody Peter Mello str = "type=\"directory\" version=\"1.0\"" 16*e6d6c189SCody Peter Mello #print "BEGIN:", str 17*e6d6c189SCody Peter Mello 18*e6d6c189SCody Peter Mello while (str) { 19*e6d6c189SCody Peter Mello sub(/^[^=]*/, "", str); 20*e6d6c189SCody Peter Mello s = substr(str, 2) 21*e6d6c189SCody Peter Mello print s 22*e6d6c189SCody Peter Mello sub(/^="[^"]*"/, "", str) 23*e6d6c189SCody Peter Mello sub(/^[ \t]*/, "", str) 24*e6d6c189SCody Peter Mello } 25*e6d6c189SCody Peter Mello} 26*e6d6c189SCody Peter Mello 27*e6d6c189SCody Peter Mello# and sample result is here (on GNU/Linux Fedora core 3) 28*e6d6c189SCody Peter Mello# 29*e6d6c189SCody Peter Mello# [kbk@skuld gawk-3.1.5]$ LC_ALL=C ./gawk -f subbug.awk 30*e6d6c189SCody Peter Mello# "directory" version="1.0" 31*e6d6c189SCody Peter Mello# "1.0" 32*e6d6c189SCody Peter Mello# [kbk@skuld gawk-3.1.5]$ LC_ALL=en_US.UTF-8 ./gawk -f subbug.awk 33*e6d6c189SCody Peter Mello# "directory" version="1.0" 34*e6d6c189SCody Peter Mello# "dire 35*e6d6c189SCody Peter Mello# [kbk@skuld gawk-3.1.5]$ 36*e6d6c189SCody Peter Mello# 37*e6d6c189SCody Peter Mello# In my investigation, this bug is cause by don't release wide-string when 38*e6d6c189SCody Peter Mello# sub is executed. 39*e6d6c189SCody Peter Mello# 40*e6d6c189SCody Peter Mello# patch is here. 41*e6d6c189SCody Peter Mello# 42*e6d6c189SCody Peter Mello# --- builtin.c.orig 2005-07-27 03:07:43.000000000 +0900 43*e6d6c189SCody Peter Mello# +++ builtin.c 2006-02-26 02:07:52.000000000 +0900 44*e6d6c189SCody Peter Mello# @@ -2463,6 +2468,15 @@ sub_common(NODE *tree, long how_many, in 45*e6d6c189SCody Peter Mello# t->stptr = buf; 46*e6d6c189SCody Peter Mello# t->stlen = textlen; 47*e6d6c189SCody Peter Mello# 48*e6d6c189SCody Peter Mello# +#ifdef MBS_SUPPORT 49*e6d6c189SCody Peter Mello# + if (t->flags & WSTRCUR) { 50*e6d6c189SCody Peter Mello# + if (t->wstptr != NULL) 51*e6d6c189SCody Peter Mello# + free(t->wstptr); 52*e6d6c189SCody Peter Mello# + t->wstptr = NULL; 53*e6d6c189SCody Peter Mello# + t->wstlen = 0; 54*e6d6c189SCody Peter Mello# + t->flags &= ~WSTRCUR; 55*e6d6c189SCody Peter Mello# + } 56*e6d6c189SCody Peter Mello# +#endif 57*e6d6c189SCody Peter Mello# free_temp(s); 58*e6d6c189SCody Peter Mello# if (matches > 0 && lhs) { 59*e6d6c189SCody Peter Mello# if (priv) { 60*e6d6c189SCody Peter Mello# 61*e6d6c189SCody Peter Mello# 62*e6d6c189SCody Peter Mello# -- 63*e6d6c189SCody Peter Mello# KIMURA Koichi 64*e6d6c189SCody Peter Mello# 65*e6d6c189SCody Peter Mello# 66*e6d6c189SCody Peter Mello# ##################################################################################### 67*e6d6c189SCody Peter Mello# This Mail Was Scanned by 012.net AntiVirus Service1- Powered by TrendMicro Interscan 68*e6d6c189SCody Peter Mello# 69