From: Tim Peters Date: Thu, 29 Jul 2004 02:28:42 +0000 (+0000) Subject: PyList_New(): we went to all the trouble of computing and bounds-checking X-Git-Tag: v2.4a2~113 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3986d4e66022b8b1821f517723cf25ca98134d0e;p=python PyList_New(): we went to all the trouble of computing and bounds-checking 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. --- diff --git a/Objects/listobject.c b/Objects/listobject.c index ac8cd335a4..4db3070e8c 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -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;