1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-27 04:40:59 +01:00

23165: fix problems with bases: error if over 36 and don't interpret octal

This commit is contained in:
Peter Stephenson 2007-02-12 16:43:40 +00:00
parent 9ed500a1cd
commit 2c92d005d7
5 changed files with 51 additions and 10 deletions

View file

@ -1,3 +1,9 @@
2007-02-10 Peter Stephenson <p.w.stephenson@ntlworld.com>
23165: Src/math.c, Src/utils.c, Doc/Zsh/options.yo: don't
try to parse base indicators in octal and raise error for
bases above 36.
2007-02-10 Felix Rosencrantz <f.rosencrantz@gmail.com> 2007-02-10 Felix Rosencrantz <f.rosencrantz@gmail.com>
* 23164: Src/builtin.c when PUSHD_SILENT is set, don't print anything * 23164: Src/builtin.c when PUSHD_SILENT is set, don't print anything
from popd/pushd. from popd/pushd.

View file

@ -1101,6 +1101,10 @@ Interpret any integer constant beginning with a 0 as octal, per IEEE Std
1003.2-1992 (ISO 9945-2:1993). This is not enabled by default as it 1003.2-1992 (ISO 9945-2:1993). This is not enabled by default as it
causes problems with parsing of, for example, date and time strings with causes problems with parsing of, for example, date and time strings with
leading zeroes. leading zeroes.
Sequences of digits indicating a numeric base such as the `tt(08)'
component in `tt(08#77)' are always interpreted as decimal, regardless
of leading zeroes.
) )
pindex(TYPESET_SILENT) pindex(TYPESET_SILENT)
item(tt(TYPESET_SILENT))( item(tt(TYPESET_SILENT))(

View file

@ -216,17 +216,33 @@ lexconstant(void)
lastbase = 16; lastbase = 16;
return NUM; return NUM;
} }
else if (isset(OCTALZEROES) && else if (isset(OCTALZEROES))
(memchr(nptr, '.', strlen(nptr)) == NULL) && {
idigit(*nptr)) { char *ptr2;
yyval.u.l = zstrtol(ptr, &ptr, 0);
lastbase = 8; /*
return NUM; * Make sure this is a real octal constant;
* it can't be a base indication (always decimal)
* or a floating point number.
*/
for (ptr2 = nptr; idigit(*ptr2); ptr2++)
;
if (ptr2 > nptr && *ptr2 != '.' && *ptr2 != 'e' &&
*ptr2 != 'E' && *ptr2 != '#')
{
yyval.u.l = zstrtol(ptr, &ptr, 0);
lastbase = 8;
return NUM;
}
nptr = ptr2;
} }
} }
else
while (idigit(*nptr)) {
nptr++; while (idigit(*nptr))
nptr++;
}
if (*nptr == '.' || *nptr == 'e' || *nptr == 'E') { if (*nptr == '.' || *nptr == 'e' || *nptr == 'E') {
/* it's a float */ /* it's a float */

View file

@ -1803,7 +1803,10 @@ zstrtol(const char *s, char **t, int base)
base = 8; base = 8;
} }
inp = s; inp = s;
if (base <= 10) if (base > 36) {
zerr("invalid base: %d", base);
return (zlong)0;
} else if (base <= 10)
for (; *s >= '0' && *s < ('0' + base); s++) { for (; *s >= '0' && *s < ('0' + base); s++) {
if (trunc) if (trunc)
continue; continue;

View file

@ -136,3 +136,15 @@
print $(( 5, (3 + 7, 4) )) print $(( 5, (3 + 7, 4) ))
0:commas and parentheses, part 1 0:commas and parentheses, part 1
>4 >4
(setopt octalzeroes; print $(( 08#77 )))
0:octalzeroes doesn't affect bases
>63
print $(( 36#z ))
0:bases up to 36 work
>35
print $(( 37#z ))
1:bases beyond 36 don't work
?(eval):1: invalid base: 37