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