From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12187 invoked by alias); 10 Oct 2010 17:48:00 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28340 Received: (qmail 12138 invoked from network); 10 Oct 2010 17:47:54 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at ntlworld.com designates 81.103.221.56 as permitted sender) Date: Sun, 10 Oct 2010 18:20:40 +0100 From: Peter Stephenson To: zsh workers Subject: Re: word[-1]= breaks on multibyte? Message-ID: <20101010182040.5a15ce2b@pws-pc> In-Reply-To: References: X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Cloudmark-Analysis: v=1.1 cv=DhNl2YeytwJssBBGe49HJX82LNDFEEVkpVB34RXKaPo= c=1 sm=0 a=TbKFYGY0iBkA:10 a=4YI7mmuYAqcA:10 a=IkcTkHD0fZMA:10 a=pGLkceISAAAA:8 a=NLZqzBF-AAAA:8 a=wer_FhfNtxHcKyvB_8gA:9 a=XJfub9NDpsGfYBEfqPkA:7 a=of3tWNf1yv-1nRLVMVRRox_PYfIA:4 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10 a=_dQi-Dcv4p4A:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 On Fri, 8 Oct 2010 23:20:30 +0200 Mikael Magnusson wrote: > % word=3Dabc=E3=81=BE > % word[-1]=3D > % echo $word > abc=C2=BE The end index is recorded as the last character, not one beyond it. We need to increment it when we use it. For assignment that's not done properly. It looked like there might have been a problem with indexing off the end even without multibyte characters at that point. There are no other references to MULTIBYTE_SUPPORT in params.c, so I wouldn't be surprised if there were other problems like this. Index: Src/params.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/zsh/zsh/Src/params.c,v retrieving revision 1.162 diff -p -u -r1.162 params.c --- Src/params.c 31 Aug 2010 19:32:57 -0000 1.162 +++ Src/params.c 10 Oct 2010 17:16:40 -0000 @@ -2275,9 +2275,22 @@ setstrvalue(Value v, char *val) if (v->start > zlen) v->start =3D zlen; if (v->end < 0) { - v->end +=3D zlen + 1; - if (v->end < 0) + v->end +=3D zlen; + if (v->end < 0) { v->end =3D 0; + } else if (v->end >=3D zlen) { + v->end =3D zlen; + } else { +#ifdef MULTIBYTE_SUPPORT + if (isset(MULTIBYTE)) { + v->end +=3D MB_METACHARLEN(z + v->end); + } else { + v->end++; + } +#else + v->end++; +#endif + } } else if (v->end > zlen) v->end =3D zlen; Index: Test/D07multibyte.ztst =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/zsh/zsh/Test/D07multibyte.ztst,v retrieving revision 1.34 diff -p -u -r1.34 D07multibyte.ztst --- Test/D07multibyte.ztst 24 Jul 2009 18:35:53 -0000 1.34 +++ Test/D07multibyte.ztst 10 Oct 2010 17:16:40 -0000 @@ -447,3 +447,21 @@ print $(( [#16] #REPLY )) 0:read passes through invalid multibyte characters >0xC5 + + word=3Dabc=E3=81=BE =20 + word[-1]=3D + print $word + word=3Dabc=E3=81=BE=20 + word[-2]=3D + print $word + word=3Dabc=E3=81=BE=20 + word[4]=3Dd + print $word + word=3Dabc=E3=81=BE=20 + word[3]=3Dnot_c + print $word =20 +0:assignment with negative indices +>abc +>ab=E3=81=BE +>abcd +>abnot_c=E3=81=BE --=20 Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/