From 641efd396e6e7b8a942d9eecd386931d3818c2ce Mon Sep 17 00:00:00 2001 From: Moshe Zadka Date: Fri, 30 Mar 2001 18:27:11 +0000 Subject: Fixed bug in complex(). No SF id --- Misc/NEWS | 3 +++ Python/bltinmodule.c | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index 835183d..c20900f 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 4ca1310..2f69d24 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; -- cgit v0.12