From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19198 invoked from network); 1 Oct 2004 18:23:29 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 1 Oct 2004 18:23:29 -0000 Received: (qmail 4017 invoked from network); 1 Oct 2004 18:23:23 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 1 Oct 2004 18:23:23 -0000 Received: (qmail 7547 invoked by alias); 1 Oct 2004 18:23:09 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 20435 Received: (qmail 7533 invoked from network); 1 Oct 2004 18:23:08 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 1 Oct 2004 18:23:08 -0000 Received: (qmail 3657 invoked from network); 1 Oct 2004 18:23:08 -0000 Received: from lhuumrelay3.lnd.ops.eu.uu.net (62.189.58.19) by a.mx.sunsite.dk with SMTP; 1 Oct 2004 18:23:07 -0000 Received: from MAILSWEEPER01.csr.com (mailhost1.csr.com [62.189.183.235]) by lhuumrelay3.lnd.ops.eu.uu.net (8.11.0/8.11.0) with ESMTP id i91IN6v09254 for ; Fri, 1 Oct 2004 18:23:06 GMT Received: from EXCHANGE02.csr.com (unverified [192.168.137.45]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Fri, 1 Oct 2004 19:22:07 +0100 Received: from news01.csr.com ([192.168.143.38]) by EXCHANGE02.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Fri, 1 Oct 2004 19:25:04 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.12.11/8.12.11) with ESMTP id i91IMxlc009023 for ; Fri, 1 Oct 2004 19:22:59 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.12.11/8.12.11/Submit) with ESMTP id i91IMxeM009020 for ; Fri, 1 Oct 2004 19:22:59 +0100 Message-Id: <200410011822.i91IMxeM009020@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk Subject: Re: [bug] type -m '^foo' In-reply-to: References: <20041001145038.GB1772@frhdtmp102861.morse.corp.wan> Date: Fri, 01 Oct 2004 19:22:58 +0100 From: Peter Stephenson X-OriginalArrivalTime: 01 Oct 2004 18:25:04.0341 (UTC) FILETIME=[F8990850:01C4A7E3] X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 Bart Schaefer wrote: > On Fri, 1 Oct 2004, Stephane Chazelas wrote: > > > With latest CVS version as well as 4.2.0 > > > > $ type -m '(^a)' > > > > segfaults. > > This fixes the crash, but it would be better if pattry() could be > rewritten so as not to need to modify the string in place. I think this fixes it, but it's horribly complicated around there. Index: Src/pattern.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/pattern.c,v retrieving revision 1.19 diff -u -r1.19 pattern.c --- Src/pattern.c 28 May 2004 19:21:05 -0000 1.19 +++ Src/pattern.c 1 Oct 2004 18:21:16 -0000 @@ -1818,10 +1818,9 @@ syncstrp->p = (unsigned char *)zshcalloc(patinlen); while ((ret = patmatch(P_OPERAND(scan)))) { unsigned char *syncpt; - char savchar, *testptr; - char *savpatinstart = patinstart; + char *savpatinstart, *origsave, *origpatinstart; int savforce = forceerrs, savpatinlen = patinlen; - int savpatflags = patflags; + int savpatflags = patflags, synclen; forceerrs = -1; savglobdots = globdots; matchederrs = errsfound; @@ -1837,16 +1836,38 @@ */ for (syncpt = syncstrp->p; !*syncpt; syncpt++) ; - testptr = patinstart + (syncpt - syncstrp->p); - DPUTS(testptr > matchpt, "BUG: EXCSYNC failed"); - savchar = *testptr; - /* - * If this isn't really the end of the string, - * remember this for the (#e) assertion. - */ - if (savchar) + synclen = syncpt - syncstrp->p; + if (patinstart[synclen]) { + /* + * We need to truncate the string at + * this point. Copy a whole load of + * stuff to avoid modifying the string. + * This includes (at least) patinstart, + * patinput and save. + */ + origsave = save; + origpatinstart = patinstart; + + DPUTS(patinstart + synclen > matchpt, + "BUG: EXCSYNC failed"); + + savpatinstart = patinstart = + ztrduppfx(patinstart, synclen); + patinput = patinstart + + (patinput - origpatinstart); + save = patinstart + (save - origpatinstart); + /* + * If this isn't really the end of the string, + * remember this for the (#e) assertion. + */ patflags |= PAT_NOTEND; - *testptr = '\0'; + } + else + { + /* Don't need to copy, already right length */ + origsave = origpatinstart = NULL; + savpatinstart = patinstart; + } next = PATNEXT(scan); while (next && P_ISEXCLUDE(next)) { char *buf = NULL; @@ -1893,7 +1914,17 @@ break; next = PATNEXT(next); } - *testptr = savchar; + /* + * Free copied string and restore if + * we needed to truncate. + */ + if (origpatinstart) { + patinput = origpatinstart + + (patinput - patinstart); + zfree(patinstart, synclen+1); + patinstart = origpatinstart; + save = origsave; + } patflags = savpatflags; globdots = savglobdots; forceerrs = savforce; -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com **********************************************************************