* regression in $(([##16]...))? @ 2008-10-16 9:23 Stephane Chazelas 2008-10-16 9:31 ` Peter Stephenson 0 siblings, 1 reply; 3+ messages in thread From: Stephane Chazelas @ 2008-10-16 9:23 UTC (permalink / raw) To: Zsh hackers list Hiya, ~$ 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. -- Stéphane ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: regression in $(([##16]...))? 2008-10-16 9:23 regression in $(([##16]...))? Stephane Chazelas @ 2008-10-16 9:31 ` Peter Stephenson 2008-10-16 10:04 ` Stephane Chazelas 0 siblings, 1 reply; 3+ messages in thread From: Peter Stephenson @ 2008-10-16 9:31 UTC (permalink / raw) To: Zsh hackers list On Thu, 16 Oct 2008 10:23:08 +0100 Stephane Chazelas <Stephane_Chazelas@yahoo.fr> 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. 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; Index: Test/C01arith.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/C01arith.ztst,v retrieving revision 1.16 diff -u -r1.16 C01arith.ztst --- Test/C01arith.ztst 12 Jun 2008 13:45:06 -0000 1.16 +++ Test/C01arith.ztst 16 Oct 2008 09:30:04 -0000 @@ -172,3 +172,19 @@ print $(( 3 + "OK"); echo "Worked") 0:not a parse failure because not arithmetic >+ OK Worked + + fn() { + emulate -L zsh + print $(( [#16] 255 )) + print $(( [##16] 255 )) + setopt cbases + print $(( [#16] 255 )) + print $(( [##16] 255 )) + } + fn +0:doubled # in base removes radix +>16#FF +>FF +>0xFF +>FF + -- Peter Stephenson <pws@csr.com> Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: regression in $(([##16]...))? 2008-10-16 9:31 ` Peter Stephenson @ 2008-10-16 10:04 ` Stephane Chazelas 0 siblings, 0 replies; 3+ messages in thread From: Stephane Chazelas @ 2008-10-16 10:04 UTC (permalink / raw) To: Peter Stephenson; +Cc: Zsh hackers list On Thu, Oct 16, 2008 at 10:31:29AM +0100, Peter Stephenson wrote: > On Thu, 16 Oct 2008 10:23:08 +0100 > Stephane Chazelas <Stephane_Chazelas@yahoo.fr> 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-10-16 10:05 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2008-10-16 9:23 regression in $(([##16]...))? Stephane Chazelas 2008-10-16 9:31 ` Peter Stephenson 2008-10-16 10:04 ` Stephane Chazelas
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).