From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 144 invoked from network); 14 May 2008 10:43:35 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 14 May 2008 10:43:35 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 5699 invoked from network); 14 May 2008 10:43:29 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 14 May 2008 10:43:29 -0000 Received: (qmail 27195 invoked by alias); 14 May 2008 10:43:26 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25025 Received: (qmail 27181 invoked from network); 14 May 2008 10:43:26 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 14 May 2008 10:43:26 -0000 Received: from cluster-d.mailcontrol.com (cluster-d.mailcontrol.com [217.69.20.190]) by bifrost.dotsrc.org (Postfix) with ESMTP id C7F5A80ED172 for ; Wed, 14 May 2008 12:43:22 +0200 (CEST) Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly47d.srv.mailcontrol.com (MailControl) with ESMTP id m4EAhEkQ011619 for ; Wed, 14 May 2008 11:43:15 +0100 Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Wed, 14 May 2008 11:43:12 +0100 Date: Wed, 14 May 2008 11:43:12 +0100 From: Peter Stephenson To: Zsh hackers list Subject: Re: arithmetic base accepted on output but not input Message-ID: <20080514114312.66719731@news01> In-Reply-To: <20080514102253.GA6202@sc.homeunix.net> References: <20080514102253.GA6202@sc.homeunix.net> Organization: CSR X-Mailer: Claws Mail 3.3.1 (GTK+ 2.12.5; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 14 May 2008 10:43:12.0729 (UTC) FILETIME=[4EE05C90:01C8B5AF] X-Scanned-By: MailControl A-08-50-03 (www.mailcontrol.com) on 10.68.0.157 X-Virus-Scanned: ClamAV 0.91.2/7115/Tue May 13 23:19:43 2008 on bifrost X-Virus-Status: Clean On Wed, 14 May 2008 11:22:53 +0100 Stephane Chazelas wrote: > Hiya, > > there's a bit of a consistency issue here: > > ~$ echo $(([#50]49)) > 50#h > ~$ echo $((50#h)) > zsh: invalid base: 50 > ~$ integer -i 50 a > ~$ a=123 > ~$ echo $a > 50#2N Right, and it looks like we don't check bases below two at all. (You can sort of do base 1 just by holding up the appropriate number of fingers, but I don't feel like implementing it. Actually, that's not quite true: it would be fun to implement but awful to handle all the bug reports saying "I accidentally set the base to 1 and the system hung for a week when I tried to print out 0xffffffff". I don't see a use for base zero.) Index: Doc/Zsh/builtins.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v retrieving revision 1.105 diff -u -r1.105 builtins.yo --- Doc/Zsh/builtins.yo 8 May 2008 12:07:06 -0000 1.105 +++ Doc/Zsh/builtins.yo 14 May 2008 10:35:29 -0000 @@ -1551,7 +1551,7 @@ item(tt(-i))( Use an internal integer representation. If var(n) is nonzero it defines the output arithmetic base, otherwise it is determined by the -first assignment. +first assignment. Bases from 2 to 36 inclusive are allowed. ) item(tt(-E))( Use an internal double-precision floating point representation. On output Index: Src/builtin.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.193 diff -u -r1.193 builtin.c --- Src/builtin.c 12 May 2008 13:50:42 -0000 1.193 +++ Src/builtin.c 14 May 2008 10:35:34 -0000 @@ -1744,6 +1744,10 @@ zwarnnam(name, "bad precision value: %s", arg); return 1; } + if (pm->base < 2 || pm->base > 36) { + zwarnnam(name, "invalid base: %d", pm->base); + return 1; + } } else if (always) pm->base = 0; Index: Src/math.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/math.c,v retrieving revision 1.30 diff -u -r1.30 math.c --- Src/math.c 15 Jun 2007 10:03:58 -0000 1.30 +++ Src/math.c 14 May 2008 10:35:35 -0000 @@ -460,6 +460,10 @@ } if(*ptr != ']') goto bofs; + if (outputradix < 2 || outputradix > 36) { + zerr("invalid base: %d", outputradix); + return EOI; + } ptr++; break; } Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.189 diff -u -r1.189 utils.c --- Src/utils.c 12 May 2008 13:50:42 -0000 1.189 +++ Src/utils.c 14 May 2008 10:35:39 -0000 @@ -1834,7 +1834,7 @@ base = 8; } inp = s; - if (base > 36) { + if (base < 2 || base > 36) { zerr("invalid base: %d", base); return (zlong)0; } else if (base <= 10) -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070