commit e0b397f6b5f9021563e6309cbccda402d9afbd22
parent 7ea8af69eacf81437f7da9a8c5ae2b0c3c64dfb2
Author: Roberto Vargas <roberto.vargas@arm.com>
Date: Mon, 5 Nov 2018 11:25:41 +0000
[libc] Fix strtoul
There were very small bugs in strtoul.
Change-Id: I7a8b80d0bcba76e5c4ad38004a37c61f9fbed05c
Diffstat:
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/libc/stdlib/strtoull.c b/src/libc/stdlib/strtoull.c
@@ -25,7 +25,7 @@ strtoull(const char *s, char **end, int base)
}
if (base == 0) {
- if (*s == '0' && toupper(s[1]) == 'x')
+ if (*s == '0' && toupper(s[1]) == 'X')
base = 16;
else if (*s == '0')
base = 8;
@@ -35,14 +35,12 @@ strtoull(const char *s, char **end, int base)
if (base == 16 && *s == '0' && toupper(s[1]) == 'X')
s += 2;
- else if (base == 8 && *s == '0')
- s++;
n = 0;
- for (t = s; p = strchr(toupper(*t), digits); ++t) {
+ for (t = s; p = strchr(digits, toupper(*t)); ++t) {
if ((d = p - digits) >= base)
break;
- if (n > base/ULLONG_MAX)
+ if (n > ULLONG_MAX/base)
goto overflow;
n *= base;
if (d > ULLONG_MAX - n)