diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-08-20 17:48:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-20 17:48:47 (GMT) |
commit | 838b0e975fc2c106508eb27d19a9548533ac1e55 (patch) | |
tree | 1af711ae1073b86d4a0afbf25d2cd6cffb2b83c3 /Objects/floatobject.c | |
parent | f0e2a46349bc5a733aee58d53fa685de108b1787 (diff) | |
download | cpython-838b0e975fc2c106508eb27d19a9548533ac1e55.zip cpython-838b0e975fc2c106508eb27d19a9548533ac1e55.tar.gz cpython-838b0e975fc2c106508eb27d19a9548533ac1e55.tar.bz2 |
bpo-44954: Fix wrong result in float.fromhex corner case (GH-27834)
(cherry picked from commit 60b93d9e4922eeae25052bc15909d1f4152babde)
Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r-- | Objects/floatobject.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 7e78132..92faa7c 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -1463,8 +1463,8 @@ float_fromhex(PyTypeObject *type, PyObject *string) bits lsb, lsb-2, lsb-3, lsb-4, ... is 1. */ if ((digit & half_eps) != 0) { round_up = 0; - if ((digit & (3*half_eps-1)) != 0 || - (half_eps == 8 && (HEX_DIGIT(key_digit+1) & 1) != 0)) + if ((digit & (3*half_eps-1)) != 0 || (half_eps == 8 && + key_digit+1 < ndigits && (HEX_DIGIT(key_digit+1) & 1) != 0)) round_up = 1; else for (i = key_digit-1; i >= 0; i--) |