diff options
author | Chris Wright <chrisw@osdl.org> | 2004-06-17 18:14:53 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2004-06-17 18:14:53 -0700 |
commit | 52ce7932a8ddaef63d632210c04ce2d449884408 (patch) | |
tree | 11801acf0f4f01355ea9719faca438fdc97021ee /lib | |
parent | dcd04a003ce5bd71749d4c205f1d92e29ab7e609 (diff) | |
download | history-52ce7932a8ddaef63d632210c04ce2d449884408.tar.gz |
[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: Chris Wright <chrisw@osdl.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/vsprintf.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index b6d283372cf5f0..49692397908c4b 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -40,11 +40,14 @@ unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) if (*cp == '0') { base = 8; cp++; - if ((*cp == 'x') && isxdigit(cp[1])) { + if ((toupper(*cp) == 'X') && isxdigit(cp[1])) { cp++; base = 16; } } + } else if (base == 16) { + if (cp[0] == '0' && toupper(cp[1]) == 'X') + cp += 2; } while (isxdigit(*cp) && (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) if (*cp == '0') { base = 8; cp++; - if ((*cp == 'x') && isxdigit(cp[1])) { + if ((toupper(*cp) == 'X') && isxdigit(cp[1])) { cp++; 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) ? toupper(*cp) : *cp)-'A'+10) < base) { |