From: Moshe Zadka Date: Fri, 30 Mar 2001 18:27:11 +0000 (+0000) Subject: Fixed bug in complex(). No SF id X-Git-Tag: v2.0.1c1~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=641efd396e6e7b8a942d9eecd386931d3818c2ce;p=thirdparty%2FPython%2Fcpython.git Fixed bug in complex(). No SF id --- diff --git a/Misc/NEWS b/Misc/NEWS index 835183d0eb95..c20900f825c0 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -38,6 +38,9 @@ http://sourceforge.net/tracker/index.php?func=detail&aid=&group_id=5470&atid strings -- but this has to be done, the previous pickling scheme broke anyway. +- complex() could segfault on numeric types with NULL for float conversion. + Fixed. + What's New in Python 2.0? ========================= diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 4ca1310be213..2f69d24e968b 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -591,12 +591,18 @@ builtin_complex(PyObject *self, PyObject *args) } } else { - tmp = (*nbr->nb_float)(r); + tmp = PyNumber_Float(r); if (own_r) { Py_DECREF(r); } if (tmp == NULL) return NULL; + if (!PyFloat_Check(tmp)) { + PyErr_SetString(PyExc_TypeError, + "float(r) didn't return a float"); + Py_DECREF(tmp); + return NULL; + } cr.real = PyFloat_AsDouble(tmp); Py_DECREF(tmp); cr.imag = 0.0;