From 153ef07a498264ae6f297fd05b89e8111937ec2c Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 7 Dec 2001 16:33:47 +0000 Subject: Return 'c' back to signed due to potential comparison problems Use simpler test for valid ranges Submitted by: bde --- lib/libc/stdlib/strtoull.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'lib/libc/stdlib/strtoull.c') diff --git a/lib/libc/stdlib/strtoull.c b/lib/libc/stdlib/strtoull.c index d9e3e4f..09bd8b4 100644 --- a/lib/libc/stdlib/strtoull.c +++ b/lib/libc/stdlib/strtoull.c @@ -56,9 +56,9 @@ strtoull(nptr, endptr, base) { const char *s; unsigned long long acc; - unsigned char c; + char c; unsigned long long cutoff; - int neg, any, cutlim, n; + int neg, any, cutlim; /* * See strtoq for comments as to the logic used. @@ -66,7 +66,7 @@ strtoull(nptr, endptr, base) s = nptr; do { c = *s++; - } while (isspace(c)); + } while (isspace((unsigned char)c)); if (c == '-') { neg = 1; c = *s++; @@ -90,20 +90,22 @@ strtoull(nptr, endptr, base) cutoff = ULLONG_MAX / base; cutlim = ULLONG_MAX % base; for ( ; ; c = *s++) { - if (isxdigit(c)) - n = digittoint(c); - else if (isalpha(c)) - n = (char)c - (isupper(c) ? 'A' - 10 : 'a' - 10); + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; else break; - if (n < 0 || n >= base) + if (c >= base) break; - if (any < 0 || acc > cutoff || (acc == cutoff && n > cutlim)) + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) any = -1; else { any = 1; acc *= base; - acc += n; + acc += c; } } if (any < 0) { -- cgit v1.1