strtod: Do not consume "x" in incomplete hex input
Adapted from upstream glibc commits: * 405698e946dbed472491f85867eb511eb080e05a * 43b9d657408fbf47a47934f9e7c84ed87f7f5a18 Fixes #13949
This commit is contained in:
parent
a820f1f01d
commit
f6d25a3a81
@ -674,18 +674,29 @@ INTERNAL (STRTOF) (nptr, endptr, group LOCALE_PARAM)
|
|||||||
|
|
||||||
/* If no other digit but a '0' is found the result is 0.0.
|
/* If no other digit but a '0' is found the result is 0.0.
|
||||||
Return current read pointer. */
|
Return current read pointer. */
|
||||||
if ((c < L_('0') || c > L_('9'))
|
if (!((c >= L_('0') && c <= L_('9'))
|
||||||
&& (base == 16 && (c < TOLOWER (L_('a')) || c > TOLOWER (L_('f'))))
|
|| (base == 16 && ((CHAR_TYPE) TOLOWER (c) >= L_('a')
|
||||||
|
&& (CHAR_TYPE) TOLOWER (c) <= L_('f')))
|
||||||
|
|| (
|
||||||
#ifdef USE_WIDE_CHAR
|
#ifdef USE_WIDE_CHAR
|
||||||
&& c != decimal
|
c == (wint_t) decimal
|
||||||
#else
|
#else
|
||||||
&& ({ for (cnt = 0; decimal[cnt] != '\0'; ++cnt)
|
({ for (cnt = 0; decimal[cnt] != '\0'; ++cnt)
|
||||||
if (decimal[cnt] != cp[cnt])
|
if (decimal[cnt] != cp[cnt])
|
||||||
break;
|
break;
|
||||||
decimal[cnt] != '\0'; })
|
decimal[cnt] == '\0'; })
|
||||||
#endif
|
#endif
|
||||||
&& (base == 16 && (cp == start_of_digits || TOLOWER (c) != L_('p')))
|
/* '0x.' alone is not a valid hexadecimal number.
|
||||||
&& (base != 16 && TOLOWER (c) != L_('e')))
|
'.' alone is not valid either, but that has been checked
|
||||||
|
already earlier. */
|
||||||
|
&& (base != 16
|
||||||
|
|| cp != start_of_digits
|
||||||
|
|| (cp[decimal_len] >= L_('0') && cp[decimal_len] <= L_('9'))
|
||||||
|
|| ((CHAR_TYPE) TOLOWER (cp[decimal_len]) >= L_('a')
|
||||||
|
&& (CHAR_TYPE) TOLOWER (cp[decimal_len]) <= L_('f'))))
|
||||||
|
|| (base == 16 && (cp != start_of_digits
|
||||||
|
&& (CHAR_TYPE) TOLOWER (c) == L_('p')))
|
||||||
|
|| (base != 16 && (CHAR_TYPE) TOLOWER (c) == L_('e'))))
|
||||||
{
|
{
|
||||||
tp = correctly_grouped_prefix (start_of_digits, cp, thousands, grouping);
|
tp = correctly_grouped_prefix (start_of_digits, cp, thousands, grouping);
|
||||||
/* If TP is at the start of the digits, there was no correctly
|
/* If TP is at the start of the digits, there was no correctly
|
||||||
|
Loading…
Reference in New Issue
Block a user