mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
Issue #18408: Fix list_ass_slice(), handle list_resize() failure
I tested the patch manually by injecting a fault using gdb: list items are correctly restored on failure.
This commit is contained in:
parent
9007dd7274
commit
2c40f640d9
1 changed files with 8 additions and 3 deletions
|
|
@ -644,9 +644,14 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
|
|||
memcpy(recycle, &item[ilow], s);
|
||||
|
||||
if (d < 0) { /* Delete -d items */
|
||||
memmove(&item[ihigh+d], &item[ihigh],
|
||||
(Py_SIZE(a) - ihigh)*sizeof(PyObject *));
|
||||
list_resize(a, Py_SIZE(a) + d);
|
||||
Py_ssize_t tail;
|
||||
tail = (Py_SIZE(a) - ihigh) * sizeof(PyObject *);
|
||||
memmove(&item[ihigh+d], &item[ihigh], tail);
|
||||
if (list_resize(a, Py_SIZE(a) + d) < 0) {
|
||||
memmove(&item[ihigh], &item[ihigh+d], tail);
|
||||
memcpy(&item[ilow], recycle, s);
|
||||
goto Error;
|
||||
}
|
||||
item = a->ob_item;
|
||||
}
|
||||
else if (d > 0) { /* Insert d items */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue