mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
issue 3633: Solaris allows fullwidth Unicode digits in isxdigit, so
rewrite float.fromhex to only allow ASCII hex digits on all platforms. (Tests for this are already present, but the test_float failures on Solaris hadn't been noticed before.) Reviewed by Antoine Pitrou.
This commit is contained in:
parent
892429b08b
commit
5c2bb1a7d4
1 changed files with 4 additions and 5 deletions
|
@ -1126,7 +1126,6 @@ char_from_hex(int x)
|
||||||
static int
|
static int
|
||||||
hex_from_char(char c) {
|
hex_from_char(char c) {
|
||||||
int x;
|
int x;
|
||||||
assert(isxdigit(c));
|
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case '0':
|
case '0':
|
||||||
x = 0;
|
x = 0;
|
||||||
|
@ -1355,12 +1354,12 @@ float_fromhex(PyObject *cls, PyObject *arg)
|
||||||
|
|
||||||
/* coefficient: <integer> [. <fraction>] */
|
/* coefficient: <integer> [. <fraction>] */
|
||||||
coeff_start = s;
|
coeff_start = s;
|
||||||
while (isxdigit(*s))
|
while (hex_from_char(*s) >= 0)
|
||||||
s++;
|
s++;
|
||||||
s_store = s;
|
s_store = s;
|
||||||
if (*s == '.') {
|
if (*s == '.') {
|
||||||
s++;
|
s++;
|
||||||
while (isxdigit(*s))
|
while (hex_from_char(*s) >= 0)
|
||||||
s++;
|
s++;
|
||||||
coeff_end = s-1;
|
coeff_end = s-1;
|
||||||
}
|
}
|
||||||
|
@ -1382,10 +1381,10 @@ float_fromhex(PyObject *cls, PyObject *arg)
|
||||||
exp_start = s;
|
exp_start = s;
|
||||||
if (*s == '-' || *s == '+')
|
if (*s == '-' || *s == '+')
|
||||||
s++;
|
s++;
|
||||||
if (!isdigit(*s))
|
if (!('0' <= *s && *s <= '9'))
|
||||||
goto parse_error;
|
goto parse_error;
|
||||||
s++;
|
s++;
|
||||||
while (isdigit(*s))
|
while ('0' <= *s && *s <= '9')
|
||||||
s++;
|
s++;
|
||||||
exp = strtol(exp_start, NULL, 10);
|
exp = strtol(exp_start, NULL, 10);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue