Commit 52ce7932 authored by Chris Wright's avatar Chris Wright Committed by Linus Torvalds

[PATCH] fix simple_strtoul base 16 handling

I know it's simple_strtoul, but is it meant to be that simple?  Fix up for
both simple_strtoul and simple_strtoull.

simple_strtoul(0x401b, NULL, 0) = 0x401b
simple_strtoul(0X401b, NULL, 0) = 0x0
simple_strtoul(0x401b, NULL, 16) = 0x0
simple_strtoul(0X401b, NULL, 16) = 0x0

simple_strtoull(0x401b, NULL, 0) = 0x401b
simple_strtoull(0X401b, NULL, 0) = 0x0
simple_strtoull(0x401b, NULL, 16) = 0x0
simple_strtoull(0X401b, NULL, 16) = 0x0
Signed-off-by: default avatarChris Wright <chrisw@osdl.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent dcd04a00
...@@ -40,11 +40,14 @@ unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) ...@@ -40,11 +40,14 @@ unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
if (*cp == '0') { if (*cp == '0') {
base = 8; base = 8;
cp++; cp++;
if ((*cp == 'x') && isxdigit(cp[1])) { if ((toupper(*cp) == 'X') && isxdigit(cp[1])) {
cp++; cp++;
base = 16; base = 16;
} }
} }
} else if (base == 16) {
if (cp[0] == '0' && toupper(cp[1]) == 'X')
cp += 2;
} }
while (isxdigit(*cp) && while (isxdigit(*cp) &&
(value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) { (value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) {
...@@ -88,11 +91,14 @@ unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base) ...@@ -88,11 +91,14 @@ unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base)
if (*cp == '0') { if (*cp == '0') {
base = 8; base = 8;
cp++; cp++;
if ((*cp == 'x') && isxdigit(cp[1])) { if ((toupper(*cp) == 'X') && isxdigit(cp[1])) {
cp++; cp++;
base = 16; base = 16;
} }
} }
} else if (base == 16) {
if (cp[0] == '0' && toupper(cp[1]) == 'X')
cp += 2;
} }
while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
? toupper(*cp) : *cp)-'A'+10) < base) { ? toupper(*cp) : *cp)-'A'+10) < base) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment