summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/strtol.c
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2001-12-07 16:33:47 +0000
committerache <ache@FreeBSD.org>2001-12-07 16:33:47 +0000
commit153ef07a498264ae6f297fd05b89e8111937ec2c (patch)
tree0ee33353ca59b5c4ce8509619edbc992775dbc25 /lib/libc/stdlib/strtol.c
parenta0c0edca18ced4d45b2cc8c31e159ba7535313a0 (diff)
downloadFreeBSD-src-153ef07a498264ae6f297fd05b89e8111937ec2c.zip
FreeBSD-src-153ef07a498264ae6f297fd05b89e8111937ec2c.tar.gz
Return 'c' back to signed due to potential comparison problems
Use simpler test for valid ranges Submitted by: bde
Diffstat (limited to 'lib/libc/stdlib/strtol.c')
-rw-r--r--lib/libc/stdlib/strtol.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/libc/stdlib/strtol.c b/lib/libc/stdlib/strtol.c
index 449f3c5..622f1d8 100644
--- a/lib/libc/stdlib/strtol.c
+++ b/lib/libc/stdlib/strtol.c
@@ -57,9 +57,9 @@ strtol(nptr, endptr, base)
{
const char *s;
unsigned long acc;
- unsigned char c;
+ char c;
unsigned long cutoff;
- int neg, any, cutlim, n;
+ int neg, any, cutlim;
/*
* Skip white space and pick up leading +/- sign if any.
@@ -69,7 +69,7 @@ strtol(nptr, endptr, base)
s = nptr;
do {
c = *s++;
- } while (isspace(c));
+ } while (isspace((unsigned char)c));
if (c == '-') {
neg = 1;
c = *s++;
@@ -112,20 +112,22 @@ strtol(nptr, endptr, base)
cutlim = cutoff % base;
cutoff /= 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) {
OpenPOWER on IntegriCloud