]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fixed bug in complex(). No SF id
authorMoshe Zadka <moshez@math.huji.ac.il>
Fri, 30 Mar 2001 18:27:11 +0000 (18:27 +0000)
committerMoshe Zadka <moshez@math.huji.ac.il>
Fri, 30 Mar 2001 18:27:11 +0000 (18:27 +0000)
Misc/NEWS
Python/bltinmodule.c

index 835183d0eb956ff042337c8c1276cb4015892782..c20900f825c0b511e242d96b6fda1e44644f98d4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,9 @@ http://sourceforge.net/tracker/index.php?func=detail&aid=<id>&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?
 =========================
index 4ca1310be2133be3b81b0ed26ed8977ec26cd9b8..2f69d24e968bcf001a0dc8099349e86378052e42 100644 (file)
@@ -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;