From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22341 invoked from network); 16 Oct 2008 10:05:31 -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; 16 Oct 2008 10:05:31 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 98377 invoked from network); 16 Oct 2008 10:05:22 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 16 Oct 2008 10:05:22 -0000 Received: (qmail 1255 invoked by alias); 16 Oct 2008 10:05:11 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25906 Received: (qmail 1227 invoked from network); 16 Oct 2008 10:05:07 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 16 Oct 2008 10:05:07 -0000 Received: from mail.o2.co.uk (sidious.london.02.net [82.132.130.152]) by bifrost.dotsrc.org (Postfix) with ESMTP id DFBA380524C0 for ; Thu, 16 Oct 2008 12:05:01 +0200 (CEST) Received: from sc.homeunix.net (78.105.216.138) by mail.o2.co.uk (8.0.013.3) (authenticated as stephane.chazelas) id 48BF35C508F4DDBB; Thu, 16 Oct 2008 11:04:55 +0100 Received: from chazelas by sc.homeunix.net with local (Exim 4.69) (envelope-from ) id 1KqPiw-0006CJ-S2; Thu, 16 Oct 2008 11:04:54 +0100 Date: Thu, 16 Oct 2008 11:04:54 +0100 From: Stephane Chazelas To: Peter Stephenson Cc: Zsh hackers list Subject: Re: regression in $(([##16]...))? Message-ID: <20081016100454.GC6376@sc.homeunix.net> Mail-Followup-To: Peter Stephenson , Zsh hackers list References: <20081016092308.GB6376@sc.homeunix.net> <20081016103129.77a25e33@news01> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20081016103129.77a25e33@news01> User-Agent: Mutt/1.5.16 (2007-09-19) X-Virus-Scanned: ClamAV 0.92.1/8433/Thu Oct 16 08:56:26 2008 on bifrost X-Virus-Status: Clean On Thu, Oct 16, 2008 at 10:31:29AM +0100, Peter Stephenson wrote: > On Thu, 16 Oct 2008 10:23:08 +0100 > Stephane Chazelas wrote: > > ~$ echo $(([##16]12)) > > zsh: invalid base (must be 2 to 36 inclusive): -16 > > (1)~$ echo $(([##2]12)) > > zsh: invalid base (must be 2 to 36 inclusive): -2 > > > > (4.3.6-dev-0+1004) > > > > I remember a check for the allowed bases was introduced at some > > point, that may be what broke it. > > That feature's so obscure I didn't know it was there and it's never been > tested. Obscure but quite handy, I'm surprised there's no equivalent in other shells, you have to resort to bc/dc in those. > Index: Src/math.c > =================================================================== > RCS file: /cvsroot/zsh/zsh/Src/math.c,v > retrieving revision 1.35 > diff -u -r1.35 math.c > --- Src/math.c 26 Sep 2008 09:11:30 -0000 1.35 > +++ Src/math.c 16 Oct 2008 09:30:04 -0000 > @@ -670,7 +670,8 @@ > } > if(*ptr != ']') > goto bofs; > - if (outputradix < 2 || outputradix > 36) { > + n = (outputradix < 0) ? -outputradix : outputradix; > + if (n < 2 || n > 36) { > zerr("invalid base (must be 2 to 36 inclusive): %d", > outputradix); > return EOI; [...] I've been too slow I was about to suggest to rewrite maybe a bit more legibly as: Index: Src/math.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/math.c,v retrieving revision 1.35 diff -p -u -r1.35 math.c --- Src/math.c 26 Sep 2008 09:11:30 -0000 1.35 +++ Src/math.c 16 Oct 2008 10:01:04 -0000 @@ -643,40 +643,44 @@ zzlex(void) return EOI; case '[': { - int n; - if (idigit(*ptr)) { - n = zstrtol(ptr, &ptr, 10); + int base = zstrtol(ptr, &ptr, 10); if (*ptr != ']' || !idigit(*++ptr)) { zerr("bad base syntax"); return EOI; } - yyval.u.l = zstrtol(ptr, &ptr, lastbase = n); + yyval.u.l = zstrtol(ptr, &ptr, lastbase = base); return NUM; - } - if (*ptr == '#') { - n = 1; - if (*++ptr == '#') { - n = -1; - ptr++; - } - if (!idigit(*ptr)) - goto bofs; - outputradix = n * zstrtol(ptr, &ptr, 10); } else { - bofs: + if (*ptr == '#') { + int double_hash = 0; + + if (*++ptr == '#') { + double_hash = 1; + ptr++; + } + + if (idigit(*ptr)) { + outputradix = zstrtol(ptr, &ptr, 10); + + if (outputradix < 2 || outputradix > 36) { + zerr("invalid base (must be 2 to 36 inclusive): %d", + outputradix); + return EOI; + } + + if (double_hash) + outputradix = -outputradix; + + ptr++; + + if(*ptr == ']') + break; + } + } zerr("bad output format specification"); return EOI; } - if(*ptr != ']') - goto bofs; - if (outputradix < 2 || outputradix > 36) { - zerr("invalid base (must be 2 to 36 inclusive): %d", - outputradix); - return EOI; - } - ptr++; - break; } case ' ': case '\t': Cheers, Stéphane