diff options
| author | Andrey A. Chernov <ache@FreeBSD.org> | 2001-12-02 09:15:54 +0000 |
|---|---|---|
| committer | Andrey A. Chernov <ache@FreeBSD.org> | 2001-12-02 09:15:54 +0000 |
| commit | 4bd71a3c895438d9e85930dc29d6000d8ecb59b4 (patch) | |
| tree | 01d842dd70781a93a969d31415ffff3267002efa /lib/libc/stdlib/strtol.c | |
| parent | 2985f5726be165362b0abee67826d488ae7077ad (diff) | |
Notes
Diffstat (limited to 'lib/libc/stdlib/strtol.c')
| -rw-r--r-- | lib/libc/stdlib/strtol.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/libc/stdlib/strtol.c b/lib/libc/stdlib/strtol.c index 3d196930376a..449f3c595019 100644 --- a/lib/libc/stdlib/strtol.c +++ b/lib/libc/stdlib/strtol.c @@ -59,7 +59,7 @@ strtol(nptr, endptr, base) unsigned long acc; unsigned char c; unsigned long cutoff; - int neg, any, cutlim; + int neg, any, cutlim, n; /* * Skip white space and pick up leading +/- sign if any. @@ -113,19 +113,19 @@ strtol(nptr, endptr, base) cutoff /= base; for ( ; ; c = *s++) { if (isxdigit(c)) - c = digittoint(c); - else if (isascii(c) && isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; + n = digittoint(c); + else if (isalpha(c)) + n = (char)c - (isupper(c) ? 'A' - 10 : 'a' - 10); else break; - if (c >= base) + if (n < 0 || n >= base) break; - if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + if (any < 0 || acc > cutoff || (acc == cutoff && n > cutlim)) any = -1; else { any = 1; acc *= base; - acc += c; + acc += n; } } if (any < 0) { |
