From: Sergey Fedoseev Date: Sat, 29 Dec 2018 22:31:36 +0000 (+0500) Subject: bpo-33234: Simplify list_preallocate_exact() (GH-11220) X-Git-Tag: v3.8.0a1~176 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e5f771f38138714415f665651de7e674fcebc38;p=thirdparty%2FPython%2Fcpython.git bpo-33234: Simplify list_preallocate_exact() (GH-11220) --- diff --git a/Objects/listobject.c b/Objects/listobject.c index b1f2b59db0a7..17c37ba97560 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -81,26 +81,15 @@ static int list_preallocate_exact(PyListObject *self, Py_ssize_t size) { assert(self->ob_item == NULL); + assert(size > 0); - PyObject **items; - size_t allocated; - - allocated = (size_t)size; - if (allocated > (size_t)PY_SSIZE_T_MAX / sizeof(PyObject *)) { - PyErr_NoMemory(); - return -1; - } - - if (size == 0) { - allocated = 0; - } - items = (PyObject **)PyMem_New(PyObject*, allocated); + PyObject **items = PyMem_New(PyObject*, size); if (items == NULL) { PyErr_NoMemory(); return -1; } self->ob_item = items; - self->allocated = allocated; + self->allocated = size; return 0; }