From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8107 invoked from network); 2 Nov 2008 17:21:12 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 2 Nov 2008 17:21:12 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 28484 invoked from network); 2 Nov 2008 17:21:04 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 2 Nov 2008 17:21:04 -0000 Received: (qmail 11141 invoked by alias); 2 Nov 2008 17:20:58 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25989 Received: (qmail 11130 invoked from network); 2 Nov 2008 17:20:57 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 2 Nov 2008 17:20:57 -0000 Received: from mtaout01-winn.ispmail.ntl.com (mtaout01-winn.ispmail.ntl.com [81.103.221.47]) by bifrost.dotsrc.org (Postfix) with ESMTP id AB36D80524C0 for ; Sun, 2 Nov 2008 18:20:53 +0100 (CET) Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20081102172053.RKEH21227.mtaout01-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com> for ; Sun, 2 Nov 2008 17:20:53 +0000 Received: from pws-pc ([81.107.43.40]) by aamtaout01-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20081102172053.BZYO19264.aamtaout01-winn.ispmail.ntl.com@pws-pc> for ; Sun, 2 Nov 2008 17:20:53 +0000 Date: Sun, 2 Nov 2008 17:20:41 +0000 From: Peter Stephenson To: zsh-workers Subject: Re: crash with multibyte and matcher-list Message-ID: <20081102172041.68824e1d@pws-pc> In-Reply-To: <237967ef0811011053u4b8751f4l7ab511d552ab1e39@mail.gmail.com> References: <237967ef0811011053u4b8751f4l7ab511d552ab1e39@mail.gmail.com> X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.12; 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.0 c=1 a=5_gdwf6QJRwA:10 a=A-Wcv0LH37gA:10 a=NLZqzBF-AAAA:8 a=gYl7L4GQja65D_BwYCwA:9 a=MB6buTxo-bRtG3RFqvYA:7 a=mLWoe0pVxEMn2UWKyTRxcDyDsx0A:4 a=MSl-tDqOz04A:10 a=_dQi-Dcv4p4A:10 a=LY0hPdMaydYA:10 X-Virus-Scanned: ClamAV 0.92.1/8554/Sun Nov 2 04:28:42 2008 on bifrost X-Virus-Status: Clean On Sat, 1 Nov 2008 18:53:52 +0100 "Mikael Magnusson" wrote: > GNU gdb 6.8 > This GDB was configured as "i686-pc-linux-gnu"... > (gdb) run > Starting program: /usr/local/bin/zsh -f > % autoload compinit;compinit > % zstyle ':completion:*' matcher-list 'm:{a-zA-Z}=3D{A-Za-z}' > +'r:|[._-]=3D* r:|=3D*' +'l:|=3D* r:|=3D*' > % touch $'\u51fa'{a,b} > % ls =E5=87=BA > Program received signal SIGSEGV, Segmentation fault. This is going to be a complete hotch-potch until I take a week out of my life to convert the whole thing to do multibyte character properly, but the following ought to be safer and more future-proof. The characters stored in the matcher are not handled as multibyte characters, so this is not likely to handle completion for multibyte characters any better yet. Index: Src/Zle/computil.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/Zle/computil.c,v retrieving revision 1.112 diff -u -r1.112 computil.c --- Src/Zle/computil.c 29 Oct 2008 01:33:23 -0000 1.112 +++ Src/Zle/computil.c 2 Nov 2008 17:18:27 -0000 @@ -4024,7 +4024,17 @@ * management is difficult. */ for (;;) { + MB_METACHARINIT(); for (mp =3D ms; *add; ) { + convchar_t addc; + int addlen; + + addlen =3D MB_METACHARLENCONV(add, &addc); +#ifdef MULTIBYTE_SUPPORT + if (addc =3D=3D WEOF) + addc =3D (wchar_t)(*p =3D=3D Meta ? p[1] ^ 32 : *p); +#endif + if (!(m =3D *mp)) { /* * No matcher, so just match the character @@ -4034,13 +4044,10 @@ * metacharacter? */ if (ret) { - if (*add =3D=3D Meta) { - *p++ =3D Meta; - *p++ =3D add[1]; - } else - *p++ =3D *add; + memcpy(p, add, addlen); + p +=3D addlen; } else - len +=3D (*add =3D=3D Meta) ? 2 : 1; + len +=3D addlen; } else if (m->flags & CMF_RIGHT) { /* * Right-anchored: match anything followed @@ -4049,16 +4056,12 @@ if (ret) { *p++ =3D '*'; /* TODO: quote again? */ - if (*add =3D=3D Meta) { - *p++ =3D Meta; - *p++ =3D add[1]; - } else - *p++ =3D *add; + memcpy(p, add, addlen); + p +=3D addlen; } else - len +=3D (*add =3D=3D Meta) ? 3 : 2; + len +=3D addlen + 1; } else { /* The usual set of matcher possibilities. */ - int chr =3D (*add =3D=3D Meta) ? add[1] ^ 32 : *add; int ind; if (m->line->tp =3D=3D CPAT_EQUIV && m->word->tp =3D=3D CPAT_EQUIV) { @@ -4073,21 +4076,17 @@ */ if (ret) { *p++ =3D '['; - if (*add =3D=3D Meta) { - *p++ =3D Meta; - *p++ =3D add[1]; - } else - *p++ =3D *add; + memcpy(p, add, addlen); + p +=3D addlen; } else - len +=3D (*add =3D=3D Meta) ? 3 : 2; - if (PATMATCHRANGE(m->line->u.str, CONVCAST(chr), - &ind, &mt)) { + len +=3D addlen + 1; + if (PATMATCHRANGE(m->line->u.str, addc, &ind, &mt)) { /* * Find the equivalent match for ind in the * word pattern. */ if ((ind =3D pattern_match_equivalence - (m->word, ind, mt, CONVCAST(chr))) !=3D -1) { + (m->word, ind, mt, addc)) !=3D -1) { if (ret) { if (imeta(ind)) { *p++ =3D Meta; @@ -4159,7 +4158,7 @@ * if *add is ] and ] is also the first * character in the range. */ - addadd =3D !pattern_match1(m->word, CONVCAST(chr), &mt); + addadd =3D !pattern_match1(m->word, addc, &mt); if (addadd && *add =3D=3D ']') { if (ret) *p++ =3D *add; @@ -4196,13 +4195,10 @@ } if (addadd && *add !=3D ']') { if (ret) { - if (imeta(*add)) { - *p++ =3D Meta; - *p++ =3D *add ^ 32; - } else - *p++ =3D *add; + memcpy(p, add, addlen); + p +=3D addlen; } else - len +=3D imeta(*add) ? 2 : 1; + len +=3D addlen; } if (ret) *p++ =3D ']'; @@ -4219,13 +4215,8 @@ } } } - if (*add =3D=3D Meta) { - add +=3D 2; - mp +=3D 2; - } else { - add++; - mp++; - } + add +=3D addlen; + mp++; } if (ret) { *p =3D '\0'; --=20 Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/