From cb356c2ecc0528d47fee2b9f4b32da4fcfb48b3a Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 11 Sep 2017 23:08:49 -0700 Subject: [PATCH] [3.6] bpo-31373: remove overly strict float range checks (GH-3486) (#3495) This undoes a853a8ba7850381d49b284295dd6f0dc491dbe44 except for the pytime.c parts. We want to continue to allow IEEE 754 doubles larger than FLT_MAX to be rounded into finite floats. Tests were added to very this behavior. (cherry picked from commit 2bb69a5b4e7f96cb35d1b28aa7b7b3974b351f59) --- Lib/test/test_float.py | 6 ++++++ Lib/test/test_getargs2.py | 6 ++++++ Objects/floatobject.c | 4 ++-- Python/getargs.c | 4 ---- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 6491f458c3..c5ca50c8f7 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -613,6 +613,12 @@ class IEEEFormatTestCase(unittest.TestCase): (' FLT_MAX && !Py_IS_INFINITY(x)) + if (Py_IS_INFINITY(y) && !Py_IS_INFINITY(x)) goto Overflow; unsigned char s[sizeof(float)]; - float y = (float)x; memcpy(s, &y, sizeof(float)); if ((float_format == ieee_little_endian_format && !le) diff --git a/Python/getargs.c b/Python/getargs.c index 8fb19f34ec..1381964206 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -811,10 +811,6 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, double dval = PyFloat_AsDouble(arg); if (PyErr_Occurred()) RETURN_ERR_OCCURRED; - else if (dval > FLT_MAX) - *p = (float)INFINITY; - else if (dval < -FLT_MAX) - *p = (float)-INFINITY; else *p = (float) dval; break; -- 2.50.1