From 2c92d005d7c0b828dc9bec3f220543b716dad6ee Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 12 Feb 2007 16:43:40 +0000 Subject: 23165: fix problems with bases: error if over 36 and don't interpret octal --- Src/math.c | 34 +++++++++++++++++++++++++--------- Src/utils.c | 5 ++++- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'Src') diff --git a/Src/math.c b/Src/math.c index 809999f9c..66d57fd53 100644 --- a/Src/math.c +++ b/Src/math.c @@ -216,17 +216,33 @@ lexconstant(void) lastbase = 16; return NUM; } - else if (isset(OCTALZEROES) && - (memchr(nptr, '.', strlen(nptr)) == NULL) && - idigit(*nptr)) { - yyval.u.l = zstrtol(ptr, &ptr, 0); - lastbase = 8; - return NUM; + else if (isset(OCTALZEROES)) + { + char *ptr2; + + /* + * 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; } } - - while (idigit(*nptr)) - nptr++; + else + { + while (idigit(*nptr)) + nptr++; + } if (*nptr == '.' || *nptr == 'e' || *nptr == 'E') { /* it's a float */ diff --git a/Src/utils.c b/Src/utils.c index 2ea8ba991..0e7a7d2bb 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -1803,7 +1803,10 @@ zstrtol(const char *s, char **t, int base) base = 8; } 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++) { if (trunc) continue; -- cgit 1.4.1