]> granicus.if.org Git - python/commitdiff
PyList_New(): we went to all the trouble of computing and bounds-checking
authorTim Peters <tim.peters@gmail.com>
Thu, 29 Jul 2004 02:28:42 +0000 (02:28 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 29 Jul 2004 02:28:42 +0000 (02:28 +0000)
the size_t nbytes, and passed nbytes to malloc, so it was confusing to
effectively recompute the same thing from scratch in the memset call.

Objects/listobject.c

index ac8cd335a4e77307e0d04412b8ea9304fa8d1dc1..4db3070e8c7d09826244034e07223eb4442c298d 100644 (file)
@@ -59,6 +59,7 @@ PyList_New(int size)
 {
        PyListObject *op;
        size_t nbytes;
+
        if (size < 0) {
                PyErr_BadInternalCall();
                return NULL;
@@ -82,7 +83,7 @@ PyList_New(int size)
                op->ob_item = (PyObject **) PyMem_MALLOC(nbytes);
                if (op->ob_item == NULL)
                        return PyErr_NoMemory();
-               memset(op->ob_item, 0, sizeof(*op->ob_item) * size);
+               memset(op->ob_item, 0, nbytes);
        }
        op->ob_size = size;
        op->allocated = size;