C99 states that the 0x or 0X prefix is optional so we should only
consume the prefix if the following character is a valid hex char.
This is equivalent to the fix in FreeBSD but I used isxdigit(3).
- todd
Index: lib/libc/stdlib/strtoimax.c
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/strtoimax.c,v
retrieving revision 1.3
diff -u -p -u -r1.3 strtoimax.c
--- lib/libc/stdlib/strtoimax.c 12 Sep 2015 16:23:14 -0000 1.3
+++ lib/libc/stdlib/strtoimax.c 5 Jul 2017 22:58:33 -0000
@@ -74,8 +74,8 @@ strtoimax(const char *nptr, char **endpt
if (c == '+')
c = *s++;
}
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ if ((base == 0 || base == 16) && c == '0' &&
+ (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) {
c = s[1];
s += 2;
base = 16;
Index: lib/libc/stdlib/strtol.c
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/strtol.c,v
retrieving revision 1.11
diff -u -p -u -r1.11 strtol.c
--- lib/libc/stdlib/strtol.c 13 Sep 2015 08:31:48 -0000 1.11
+++ lib/libc/stdlib/strtol.c 5 Jul 2017 22:59:13 -0000
@@ -75,8 +75,8 @@ strtol(const char *nptr, char **endptr,
if (c == '+')
c = *s++;
}
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ if ((base == 0 || base == 16) && c == '0' &&
+ (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) {
c = s[1];
s += 2;
base = 16;
Index: lib/libc/stdlib/strtoll.c
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/strtoll.c,v
retrieving revision 1.9
diff -u -p -u -r1.9 strtoll.c
--- lib/libc/stdlib/strtoll.c 13 Sep 2015 08:31:48 -0000 1.9
+++ lib/libc/stdlib/strtoll.c 5 Jul 2017 22:59:13 -0000
@@ -77,8 +77,8 @@ strtoll(const char *nptr, char **endptr,
if (c == '+')
c = *s++;
}
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ if ((base == 0 || base == 16) && c == '0' &&
+ (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) {
c = s[1];
s += 2;
base = 16;
Index: lib/libc/stdlib/strtoul.c
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/strtoul.c,v
retrieving revision 1.10
diff -u -p -u -r1.10 strtoul.c
--- lib/libc/stdlib/strtoul.c 13 Sep 2015 08:31:48 -0000 1.10
+++ lib/libc/stdlib/strtoul.c 5 Jul 2017 22:59:13 -0000
@@ -69,8 +69,8 @@ strtoul(const char *nptr, char **endptr,
if (c == '+')
c = *s++;
}
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ if ((base == 0 || base == 16) && c == '0' &&
+ (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) {
c = s[1];
s += 2;
base = 16;
Index: lib/libc/stdlib/strtoull.c
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/strtoull.c,v
retrieving revision 1.8
diff -u -p -u -r1.8 strtoull.c
--- lib/libc/stdlib/strtoull.c 13 Sep 2015 08:31:48 -0000 1.8
+++ lib/libc/stdlib/strtoull.c 5 Jul 2017 22:59:13 -0000
@@ -71,8 +71,8 @@ strtoull(const char *nptr, char **endptr
if (c == '+')
c = *s++;
}
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ if ((base == 0 || base == 16) && c == '0' &&
+ (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) {
c = s[1];
s += 2;
base = 16;
Index: lib/libc/stdlib/strtoumax.c
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/strtoumax.c,v
retrieving revision 1.3
diff -u -p -u -r1.3 strtoumax.c
--- lib/libc/stdlib/strtoumax.c 12 Sep 2015 16:23:14 -0000 1.3
+++ lib/libc/stdlib/strtoumax.c 5 Jul 2017 22:59:13 -0000
@@ -68,8 +68,8 @@ strtoumax(const char *nptr, char **endpt
if (c == '+')
c = *s++;
}
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ if ((base == 0 || base == 16) && c == '0' &&
+ (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) {
c = s[1];
s += 2;
base = 16;