From a4baf1c543bca261c27e98ba296e42665f3cb872 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Fri, 8 Sep 2017 21:53:04 -0700 Subject: [3.6] bpo-26669: Fix nan arg value error in pytime.c (GH-3085) (GH-3467) * Modify NaN check function and error message * Fix pytime.c when arg is nan * fix whitespace (cherry picked from commit 829dacce4fca60fc3c3367980e75e21dfcdbe6be) --- Python/pytime.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Python/pytime.c') diff --git a/Python/pytime.c b/Python/pytime.c index 387657af2c..b416eff6b2 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -133,6 +133,11 @@ _PyTime_ObjectToDenominator(PyObject *obj, time_t *sec, long *numerator, if (PyFloat_Check(obj)) { double d = PyFloat_AsDouble(obj); + if (Py_IS_NAN(d)) { + *numerator = 0; + PyErr_SetString(PyExc_ValueError, "Invalid value NaN (not a number)"); + return -1; + } return _PyTime_DoubleToDenominator(d, sec, numerator, denominator, round); } @@ -154,6 +159,11 @@ _PyTime_ObjectToTime_t(PyObject *obj, time_t *sec, _PyTime_round_t round) volatile double d; d = PyFloat_AsDouble(obj); + if (Py_IS_NAN(d)) { + PyErr_SetString(PyExc_ValueError, "Invalid value NaN (not a number)"); + return -1; + } + d = _PyTime_Round(d, round); (void)modf(d, &intpart); @@ -301,6 +311,10 @@ _PyTime_FromObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round, if (PyFloat_Check(obj)) { double d; d = PyFloat_AsDouble(obj); + if (Py_IS_NAN(d)) { + PyErr_SetString(PyExc_ValueError, "Invalid value NaN (not a number)"); + return -1; + } return _PyTime_FromFloatObject(t, d, round, unit_to_ns); } else { -- cgit v1.2.1