Return 'c' back to signed due to potential comparison problems

Use simpler test for valid ranges

Submitted by:	bde
This commit is contained in:
Andrey A. Chernov 2001-12-07 16:33:47 +00:00
parent 6cbb6156c3
commit f34b139cda
6 changed files with 72 additions and 60 deletions

View File

@ -56,9 +56,9 @@ strtoimax(nptr, endptr, base)
{
const char *s;
uintmax_t acc;
unsigned char c;
char c;
uintmax_t cutoff;
int neg, any, cutlim, n;
int neg, any, cutlim;
/*
* Skip white space and pick up leading +/- sign if any.
@ -68,7 +68,7 @@ strtoimax(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 @@ strtoimax(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) {

View File

@ -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) {

View File

@ -56,9 +56,9 @@ strtoll(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;
/*
* Skip white space and pick up leading +/- sign if any.
@ -68,7 +68,7 @@ strtoll(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 @@ strtoll(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) {

View File

@ -56,9 +56,9 @@ strtoul(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;
/*
* See strtol for comments as to the logic used.
@ -66,7 +66,7 @@ strtoul(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 @@ strtoul(nptr, endptr, base)
cutoff = ULONG_MAX / base;
cutlim = ULONG_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) {

View File

@ -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) {

View File

@ -56,9 +56,9 @@ strtoumax(nptr, endptr, base)
{
const char *s;
uintmax_t acc;
unsigned char c;
char c;
uintmax_t cutoff;
int neg, any, cutlim, n;
int neg, any, cutlim;
/*
* See strtoimax for comments as to the logic used.
@ -66,7 +66,7 @@ strtoumax(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 @@ strtoumax(nptr, endptr, base)
cutoff = UINTMAX_MAX / base;
cutlim = UINTMAX_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) {