diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-07-19 21:06:21 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-07-19 21:06:21 (GMT) |
commit | 2c40f640d95542c7d63f8ce2d5c00c5381d8a5c3 (patch) | |
tree | 8d6ae91ec1697d9386ec1b2cf2aca64b0f9770de /Objects | |
parent | 9007dd7274efe34c123c0c6d874f5395e3cfeb7f (diff) | |
download | cpython-2c40f640d95542c7d63f8ce2d5c00c5381d8a5c3.zip cpython-2c40f640d95542c7d63f8ce2d5c00c5381d8a5c3.tar.gz cpython-2c40f640d95542c7d63f8ce2d5c00c5381d8a5c3.tar.bz2 |
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.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/listobject.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index ce6b708..2f203b3 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -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 */ |