* arithmetic base accepted on output but not input
@ 2008-05-14 10:22 Stephane Chazelas
2008-05-14 10:43 ` Peter Stephenson
0 siblings, 1 reply; 4+ messages in thread
From: Stephane Chazelas @ 2008-05-14 10:22 UTC (permalink / raw)
To: Zsh hackers list
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
Cheers,
Stéphane
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: arithmetic base accepted on output but not input
2008-05-14 10:22 arithmetic base accepted on output but not input Stephane Chazelas
@ 2008-05-14 10:43 ` Peter Stephenson
2008-06-07 18:43 ` Richard Hartmann
0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2008-05-14 10:43 UTC (permalink / raw)
To: Zsh hackers list
On Wed, 14 May 2008 11:22:53 +0100
Stephane Chazelas <Stephane_Chazelas@yahoo.fr> 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 <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] 4+ messages in thread
* Re: arithmetic base accepted on output but not input
2008-05-14 10:43 ` Peter Stephenson
@ 2008-06-07 18:43 ` Richard Hartmann
2008-06-10 8:42 ` Peter Stephenson
0 siblings, 1 reply; 4+ messages in thread
From: Richard Hartmann @ 2008-06-07 18:43 UTC (permalink / raw)
Cc: Zsh hackers list
On Wed, May 14, 2008 at 12:43 PM, Peter Stephenson <pws@csr.com> wrote:
> + if (pm->base < 2 || pm->base > 36) {
> + zwarnnam(name, "invalid base: %d", pm->base);
> + return 1;
> + }
Could you make the error messages state what range, i.e. 2 to 36,
is allowed, please? Verbose error messages are a great thing :)
Thanks,
Richard
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: arithmetic base accepted on output but not input
2008-06-07 18:43 ` Richard Hartmann
@ 2008-06-10 8:42 ` Peter Stephenson
0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2008-06-10 8:42 UTC (permalink / raw)
To: Zsh hackers list
"Richard Hartmann" wrote:
> On Wed, May 14, 2008 at 12:43 PM, Peter Stephenson <pws@csr.com> wrote:
>
> > + if (pm->base < 2 || pm->base > 36) {
> > + zwarnnam(name, "invalid base: %d", pm->base);
> > + return 1;
> > + }
>
> Could you make the error messages state what range, i.e. 2 to 36,
> is allowed, please? Verbose error messages are a great thing :)
OK
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.195
diff -u -r1.195 builtin.c
--- Src/builtin.c 15 May 2008 15:51:01 -0000 1.195
+++ Src/builtin.c 10 Jun 2008 08:41:28 -0000
@@ -1745,7 +1745,8 @@
return 1;
}
if (pm->base < 2 || pm->base > 36) {
- zwarnnam(name, "invalid base: %d", pm->base);
+ zwarnnam(name, "invalid base (must be 2 to 36 inclusive): %d",
+ pm->base);
return 1;
}
} else if (always)
Index: Src/math.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/math.c,v
retrieving revision 1.31
diff -u -r1.31 math.c
--- Src/math.c 14 May 2008 10:48:28 -0000 1.31
+++ Src/math.c 10 Jun 2008 08:41:28 -0000
@@ -461,7 +461,8 @@
if(*ptr != ']')
goto bofs;
if (outputradix < 2 || outputradix > 36) {
- zerr("invalid base: %d", outputradix);
+ zerr("invalid base (must be 2 to 36 inclusive): %d",
+ outputradix);
return EOI;
}
ptr++;
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.193
diff -u -r1.193 utils.c
--- Src/utils.c 17 May 2008 22:43:27 -0000 1.193
+++ Src/utils.c 10 Jun 2008 08:41:28 -0000
@@ -1844,7 +1844,7 @@
}
inp = s;
if (base < 2 || base > 36) {
- zerr("invalid base: %d", base);
+ zerr("invalid base (must be 2 to 36 inclusive): %d", base);
return (zlong)0;
} else if (base <= 10)
for (; *s >= '0' && *s < ('0' + base); s++) {
--
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] 4+ messages in thread
end of thread, other threads:[~2008-06-10 8:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-14 10:22 arithmetic base accepted on output but not input Stephane Chazelas
2008-05-14 10:43 ` Peter Stephenson
2008-06-07 18:43 ` Richard Hartmann
2008-06-10 8:42 ` Peter Stephenson
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).