summaryrefslogtreecommitdiffstats
path: root/Python/pytime.c
diff options
context:
space:
mode:
authorHan Lee <hanlee.dev@gmail.com>2017-09-08 23:05:05 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-09-08 23:05:05 (GMT)
commit829dacce4fca60fc3c3367980e75e21dfcdbe6be (patch)
tree749ad4b2cb18866dce40da6cfb4b53b0424b8041 /Python/pytime.c
parente6eb48c10dc389d1d70657593de6a6cb3087d3d1 (diff)
downloadcpython-829dacce4fca60fc3c3367980e75e21dfcdbe6be.zip
cpython-829dacce4fca60fc3c3367980e75e21dfcdbe6be.tar.gz
cpython-829dacce4fca60fc3c3367980e75e21dfcdbe6be.tar.bz2
bpo-26669: Fix nan arg value error in pytime.c (#3085)
* Fix #26669 * Modify NaN check function and error message * Fix pytime.c when arg is nan * fix whitespace
Diffstat (limited to 'Python/pytime.c')
-rw-r--r--Python/pytime.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Python/pytime.c b/Python/pytime.c
index f3c9132..7edb534 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 {