From ff3a76fcf6817a6df6bb11df1e251363e59e9b9e Mon Sep 17 00:00:00 2001 From: mccabe Date: Wed, 3 Jun 1998 06:08:21 +0000 Subject: [PATCH] Reinstated backed-out changes. --- js/ref/jsnum.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/js/ref/jsnum.c b/js/ref/jsnum.c index ddec4779c7f..26b492eec20 100644 --- a/js/ref/jsnum.c +++ b/js/ref/jsnum.c @@ -97,7 +97,7 @@ num_parseFloat(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, return JS_TRUE; } -/* See ECMA 15.1.2.2 */ +/* See ECMA 15.1.2.2. */ static JSBool num_parseInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { @@ -105,7 +105,8 @@ num_parseInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) jsint radix; const jschar *chars, *start; jsdouble sum; - intN negative, digit, newDigit; + JSBool negative; + uintN digit, newDigit; jschar c; jschar digitMax = '9'; jschar lowerCaseBound = 'a'; @@ -115,7 +116,12 @@ num_parseInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) if (!str) return JS_FALSE; chars = str->chars; - while (JS_ISSPACE(*chars) && *chars != 0) + + /* This assumes that the char strings are null-terminated - JS_ISSPACE will + * always evaluate to false at the end of a string containing only + * whitespace. + */ + while (JS_ISSPACE(*chars)) chars++; if ((negative = (*chars == '-')) != 0 || *chars == '+') @@ -143,10 +149,9 @@ num_parseInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) /* No radix supplied, or some radix that evaluated to 0. */ if (*chars == '0') { /* It's either hex or octal; only increment char if str isn't '0' */ - if ((*(chars + 1) != 0) && - (*(++chars) == 'X' || *chars == 'x')) /* Hex */ + if (*(chars + 1) == 'X' || *(chars + 1) == 'x') /* Hex */ { - chars++; + chars += 2; radix = 16; } else { /* Octal */ radix = 8; @@ -176,7 +181,7 @@ num_parseInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) } digit = 0; /* how many digits have we seen? (if radix == 10) */ sum = 0; - while ((c = *chars) != 0) { + while ((c = *chars) != 0) { /* 0 is never a valid character. */ if ('0' <= c && c <= digitMax) newDigit = c - '0'; else if ('a' <= c && c < lowerCaseBound)