summaryrefslogtreecommitdiffstats
path: root/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-01-27 05:44:16 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-01-27 05:44:16 (GMT)
commit3743432302e9b31d4fe0db31485543a306057fc8 (patch)
tree44b17d2b0ee2b6d75db1aaa4c931527ab1a35020 /Modules/_collectionsmodule.c
parentd4e51f45a9b82832e95dcc55ba0d8f53ca725824 (diff)
downloadcpython-3743432302e9b31d4fe0db31485543a306057fc8.zip
cpython-3743432302e9b31d4fe0db31485543a306057fc8.tar.gz
cpython-3743432302e9b31d4fe0db31485543a306057fc8.tar.bz2
Issue #26194: Fix undefined behavior for deque.insert() when len(d) == maxlen
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r--Modules/_collectionsmodule.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 1a33428..b9c4f3b 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -973,10 +973,17 @@ deque_insert(dequeobject *deque, PyObject *args)
Py_ssize_t index;
Py_ssize_t n = Py_SIZE(deque);
PyObject *value;
+ PyObject *oldvalue;
PyObject *rv;
if (!PyArg_ParseTuple(args, "nO:insert", &index, &value))
return NULL;
+ if (deque->maxlen == Py_SIZE(deque)) {
+ if (index >= deque->maxlen || Py_SIZE(deque) == 0)
+ Py_RETURN_NONE;
+ oldvalue = deque_pop(deque, NULL);
+ Py_DECREF(oldvalue);
+ }
if (index >= n)
return deque_append(deque, value);
if (index <= -n || index == 0)