diff --git a/lib/libc/stdlib/strtoll.c b/lib/libc/stdlib/strtoll.c index b31cca4ab199..a5720df447d4 100644 --- a/lib/libc/stdlib/strtoll.c +++ b/lib/libc/stdlib/strtoll.c @@ -56,7 +56,7 @@ strtoq(nptr, endptr, base) { register const char *s; register u_quad_t acc; - register int c; + register unsigned char c; register u_quad_t qbase, cutoff; register int neg, any, cutlim; @@ -109,6 +109,8 @@ strtoq(nptr, endptr, base) cutlim = cutoff % qbase; cutoff /= qbase; for (acc = 0, any = 0;; c = *s++) { + if (!isascii(c)) + break; if (isdigit(c)) c -= '0'; else if (isalpha(c)) diff --git a/lib/libc/stdlib/strtoq.c b/lib/libc/stdlib/strtoq.c index b31cca4ab199..a5720df447d4 100644 --- a/lib/libc/stdlib/strtoq.c +++ b/lib/libc/stdlib/strtoq.c @@ -56,7 +56,7 @@ strtoq(nptr, endptr, base) { register const char *s; register u_quad_t acc; - register int c; + register unsigned char c; register u_quad_t qbase, cutoff; register int neg, any, cutlim; @@ -109,6 +109,8 @@ strtoq(nptr, endptr, base) cutlim = cutoff % qbase; cutoff /= qbase; for (acc = 0, any = 0;; c = *s++) { + if (!isascii(c)) + break; if (isdigit(c)) c -= '0'; else if (isalpha(c)) diff --git a/lib/libc/stdlib/strtoul.c b/lib/libc/stdlib/strtoul.c index e60556c0aa50..0bf6b82ef085 100644 --- a/lib/libc/stdlib/strtoul.c +++ b/lib/libc/stdlib/strtoul.c @@ -54,7 +54,7 @@ strtoul(nptr, endptr, base) { register const char *s = nptr; register unsigned long acc; - register int c; + register unsigned char c; register unsigned long cutoff; register int neg = 0, any, cutlim; @@ -80,6 +80,8 @@ strtoul(nptr, endptr, base) cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; for (acc = 0, any = 0;; c = *s++) { + if (!isascii(c)) + break; if (isdigit(c)) c -= '0'; else if (isalpha(c)) diff --git a/lib/libc/stdlib/strtoull.c b/lib/libc/stdlib/strtoull.c index ee1e13b7d7c2..16dda0be3971 100644 --- a/lib/libc/stdlib/strtoull.c +++ b/lib/libc/stdlib/strtoull.c @@ -56,7 +56,7 @@ strtouq(nptr, endptr, base) { register const char *s = nptr; register u_quad_t acc; - register int c; + register unsigned char c; register u_quad_t qbase, cutoff; register int neg, any, cutlim; @@ -87,6 +87,8 @@ strtouq(nptr, endptr, base) cutoff = (u_quad_t)UQUAD_MAX / qbase; cutlim = (u_quad_t)UQUAD_MAX % qbase; for (acc = 0, any = 0;; c = *s++) { + if (!isascii(c)) + break; if (isdigit(c)) c -= '0'; else if (isalpha(c)) diff --git a/lib/libc/stdlib/strtouq.c b/lib/libc/stdlib/strtouq.c index ee1e13b7d7c2..16dda0be3971 100644 --- a/lib/libc/stdlib/strtouq.c +++ b/lib/libc/stdlib/strtouq.c @@ -56,7 +56,7 @@ strtouq(nptr, endptr, base) { register const char *s = nptr; register u_quad_t acc; - register int c; + register unsigned char c; register u_quad_t qbase, cutoff; register int neg, any, cutlim; @@ -87,6 +87,8 @@ strtouq(nptr, endptr, base) cutoff = (u_quad_t)UQUAD_MAX / qbase; cutlim = (u_quad_t)UQUAD_MAX % qbase; for (acc = 0, any = 0;; c = *s++) { + if (!isascii(c)) + break; if (isdigit(c)) c -= '0'; else if (isalpha(c))