math.factorial depends on PyLong_AsLong correctly converting floats; rewrite
it to do the conversion explicitly instead. See issue #7550.
This commit is contained in:
parent
0732fd952b
commit
5698977186
|
@ -1082,15 +1082,22 @@ math_factorial(PyObject *self, PyObject *arg)
|
||||||
PyObject *result, *iobj, *newresult;
|
PyObject *result, *iobj, *newresult;
|
||||||
|
|
||||||
if (PyFloat_Check(arg)) {
|
if (PyFloat_Check(arg)) {
|
||||||
|
PyObject *lx;
|
||||||
double dx = PyFloat_AS_DOUBLE((PyFloatObject *)arg);
|
double dx = PyFloat_AS_DOUBLE((PyFloatObject *)arg);
|
||||||
if (dx != floor(dx)) {
|
if (!(Py_IS_FINITE(dx) && dx == floor(dx))) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"factorial() only accepts integral values");
|
"factorial() only accepts integral values");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
lx = PyLong_FromDouble(dx);
|
||||||
|
if (lx == NULL)
|
||||||
|
return NULL;
|
||||||
|
x = PyLong_AsLong(lx);
|
||||||
|
Py_DECREF(lx);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
x = PyInt_AsLong(arg);
|
||||||
|
|
||||||
x = PyInt_AsLong(arg);
|
|
||||||
if (x == -1 && PyErr_Occurred())
|
if (x == -1 && PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
|
|
Loading…
Reference in New Issue