From 2571c7f7200f06b1055c8360f17a9a0f4eca06f4 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Fri, 21 Jan 2005 00:42:13 +0000 Subject: 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 --- lib/libc/stdlib/strtoimax.c | 6 +++++- lib/libc/stdlib/strtol.c | 6 +++++- lib/libc/stdlib/strtoll.c | 6 +++++- lib/libc/stdlib/strtoul.c | 6 +++++- lib/libc/stdlib/strtoull.c | 6 +++++- lib/libc/stdlib/strtoumax.c | 6 +++++- 6 files changed, 30 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/libc/stdlib/strtoimax.c b/lib/libc/stdlib/strtoimax.c index 0cb387b64ad94..147fce2b98a3f 100644 --- a/lib/libc/stdlib/strtoimax.c +++ b/lib/libc/stdlib/strtoimax.c @@ -75,7 +75,11 @@ strtoimax(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; diff --git a/lib/libc/stdlib/strtol.c b/lib/libc/stdlib/strtol.c index 658628e370c60..5aae7f9dc0bc4 100644 --- a/lib/libc/stdlib/strtol.c +++ b/lib/libc/stdlib/strtol.c @@ -76,7 +76,11 @@ strtol(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; diff --git a/lib/libc/stdlib/strtoll.c b/lib/libc/stdlib/strtoll.c index 2eb3a509a58c8..6cbe76abae994 100644 --- a/lib/libc/stdlib/strtoll.c +++ b/lib/libc/stdlib/strtoll.c @@ -75,7 +75,11 @@ strtoll(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; diff --git a/lib/libc/stdlib/strtoul.c b/lib/libc/stdlib/strtoul.c index 2146a98b8ac05..a8e37364101b8 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; diff --git a/lib/libc/stdlib/strtoull.c b/lib/libc/stdlib/strtoull.c index 1720a8f6571c5..0e80b0d512959 100644 --- a/lib/libc/stdlib/strtoull.c +++ b/lib/libc/stdlib/strtoull.c @@ -73,7 +73,11 @@ strtoull(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; diff --git a/lib/libc/stdlib/strtoumax.c b/lib/libc/stdlib/strtoumax.c index ddaee5935a4bc..91d5d07ea4c8b 100644 --- a/lib/libc/stdlib/strtoumax.c +++ b/lib/libc/stdlib/strtoumax.c @@ -73,7 +73,11 @@ strtoumax(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; -- cgit v1.2.3