summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/strtoul.c
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2005-01-21 00:42:13 +0000
committerache <ache@FreeBSD.org>2005-01-21 00:42:13 +0000
commitb05ac67f5e11d06fc6eefd65556f036998a0a0bb (patch)
treed24a817d276208fdac47a21499eab3278d2f86ba /lib/libc/stdlib/strtoul.c
parentda1618943dd67cb16ec84958b0081c58b6005fa5 (diff)
downloadFreeBSD-src-b05ac67f5e11d06fc6eefd65556f036998a0a0bb.zip
FreeBSD-src-b05ac67f5e11d06fc6eefd65556f036998a0a0bb.tar.gz
POSIX says that 0[xX] prefix is _optional_ even in base 16 case, make it
really so. "If the value of base is 16, the characters 0x or 0X may optionally precede the sequence of letters and digits, following the sign if present." Found by: joerg
Diffstat (limited to 'lib/libc/stdlib/strtoul.c')
-rw-r--r--lib/libc/stdlib/strtoul.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/libc/stdlib/strtoul.c b/lib/libc/stdlib/strtoul.c
index 2146a98..a8e3736 100644
--- a/lib/libc/stdlib/strtoul.c
+++ b/lib/libc/stdlib/strtoul.c
@@ -73,7 +73,11 @@ strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
c = *s++;
}
if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ c == '0' && (*s == 'x' || *s == 'X') &&
+ ((s[1] >= 'a' && s[1] <= 'f') ||
+ (s[1] >= 'A' && s[1] <= 'F') ||
+ (s[1] >= '0' && s[1] <= '9'))
+ ) {
c = s[1];
s += 2;
base = 16;
OpenPOWER on IntegriCloud