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