We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d51324a commit 0e5f771Copy full SHA for 0e5f771
1 file changed
Objects/listobject.c
@@ -81,26 +81,15 @@ static int
81
list_preallocate_exact(PyListObject *self, Py_ssize_t size)
82
{
83
assert(self->ob_item == NULL);
84
+ assert(size > 0);
85
- PyObject **items;
86
- size_t allocated;
87
-
88
- allocated = (size_t)size;
89
- if (allocated > (size_t)PY_SSIZE_T_MAX / sizeof(PyObject *)) {
90
- PyErr_NoMemory();
91
- return -1;
92
- }
93
94
- if (size == 0) {
95
- allocated = 0;
96
97
- items = (PyObject **)PyMem_New(PyObject*, allocated);
+ PyObject **items = PyMem_New(PyObject*, size);
98
if (items == NULL) {
99
PyErr_NoMemory();
100
return -1;
101
}
102
self->ob_item = items;
103
- self->allocated = allocated;
+ self->allocated = size;
104
return 0;
105
106
0 commit comments