From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21791 invoked from network); 25 Jul 2007 09:22:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.1 (2007-05-02) 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.1 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 25 Jul 2007 09:22:23 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 18178 invoked from network); 25 Jul 2007 09:22:16 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 25 Jul 2007 09:22:16 -0000 Received: (qmail 28411 invoked by alias); 25 Jul 2007 09:22:14 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23696 Received: (qmail 28402 invoked from network); 25 Jul 2007 09:22:13 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 25 Jul 2007 09:22:13 -0000 Received: (qmail 17871 invoked from network); 25 Jul 2007 09:22:13 -0000 Received: from cluster-d.mailcontrol.com (217.69.20.190) by a.mx.sunsite.dk with SMTP; 25 Jul 2007 09:22:10 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly14d.srv.mailcontrol.com (MailControl) with ESMTP id l6P9M5kQ026361 for ; Wed, 25 Jul 2007 10:22:05 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Wed, 25 Jul 2007 10:22:04 +0100 Date: Wed, 25 Jul 2007 10:22:04 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: Memory access bug with negative subscripts Message-ID: <20070725102204.799d9cb2@news01.csr.com> In-Reply-To: <070724215222.ZM4902@torch.brasslantern.com> References: <070724215222.ZM4902@torch.brasslantern.com> Organization: CSR X-Mailer: Claws Mail 2.9.1 (GTK+ 2.10.12; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 25 Jul 2007 09:22:04.0793 (UTC) FILETIME=[43E9C690:01C7CE9D] X-Scanned-By: MailControl A-07-08-00 (www.mailcontrol.com) on 10.68.0.124 On Tue, 24 Jul 2007 21:52:22 -0700 Bart Schaefer wrote: > This bug appears at least as far back as zsh 3.0.5, and probably longer > ago. Still happens in the latest CVS co from SourceForge. > > x=x > x[-10]=y > print $x > > I can't predict what you'll see, but unless you get very lucky it won't > be what you ought to see. The only sensible choice seems to be to make this do what arrays do, add the element at the start. This is inconistent with assignments to subscript 0 which now cause an error, but that was quite specifically to deal with the removal of fake KSH_ARRAYS and detect an incorrect assumption of zero-offset addressing. There isn't really a logical link, anyway, since negative offsets count from the end. Index: Src/params.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/params.c,v retrieving revision 1.132 diff -u -r1.132 params.c --- Src/params.c 6 Jul 2007 21:52:39 -0000 1.132 +++ Src/params.c 25 Jul 2007 09:16:26 -0000 @@ -2076,8 +2076,11 @@ } if (v->start > zlen) v->start = zlen; - if (v->end < 0) + if (v->end < 0) { v->end += zlen + 1; + if (v->end < 0) + v->end = 0; + } else if (v->end > zlen) v->end = zlen; x = (char *) zalloc(v->start + strlen(val) + zlen - v->end + 1); Index: Test/D04parameter.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v retrieving revision 1.26 diff -u -r1.26 D04parameter.ztst --- Test/D04parameter.ztst 6 Jul 2007 13:10:45 -0000 1.26 +++ Test/D04parameter.ztst 25 Jul 2007 09:16:27 -0000 @@ -920,3 +920,20 @@ 0:Numeric sorting >a6 a17 a117 b6 b17 b117 >b117 b17 b6 a117 a17 a6 + + x=sprodj + x[-10]=scrumf + print $x +0:Out of range negative scalar subscripts +>scrumfsprodj + + a=(some sunny day) + a[-10]=(we\'ll meet again) + print -l $a +0:Out of range negative array subscripts +>we'll +>meet +>again +>some +>sunny +>day -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 .