diff options
author | Raymond Hettinger <python@rcn.com> | 2011-01-25 21:43:29 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2011-01-25 21:43:29 (GMT) |
commit | 57a8689b55ee3a26f53b4b743901b3a55b57b46c (patch) | |
tree | 9a6f76c1a36b8a510baa7b9ca4f0cf58cd326d47 /Modules | |
parent | 51581de168f1c931b144fb8c61cdfbaf2c53734f (diff) | |
download | cpython-57a8689b55ee3a26f53b4b743901b3a55b57b46c.zip cpython-57a8689b55ee3a26f53b4b743901b3a55b57b46c.tar.gz cpython-57a8689b55ee3a26f53b4b743901b3a55b57b46c.tar.bz2 |
Issue 11004: Fix edge case for deque.count().
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_collectionsmodule.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index c140e97..faa2577 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -485,7 +485,8 @@ deque_reverse(dequeobject *deque, PyObject *unused) /* Advance left block/index pair */ leftindex++; if (leftindex == BLOCKLEN) { - assert (leftblock->rightlink != NULL); + if (leftblock->rightlink == NULL) + break; leftblock = leftblock->rightlink; leftindex = 0; } @@ -493,7 +494,8 @@ deque_reverse(dequeobject *deque, PyObject *unused) /* Step backwards with the right block/index pair */ rightindex--; if (rightindex == -1) { - assert (rightblock->leftlink != NULL); + if (rightblock->leftlink == NULL) + break; rightblock = rightblock->leftlink; rightindex = BLOCKLEN - 1; } @@ -509,7 +511,7 @@ deque_count(dequeobject *deque, PyObject *v) { block *leftblock = deque->leftblock; Py_ssize_t leftindex = deque->leftindex; - Py_ssize_t n = (deque->len); + Py_ssize_t n = deque->len; Py_ssize_t i; Py_ssize_t count = 0; PyObject *item; @@ -533,7 +535,8 @@ deque_count(dequeobject *deque, PyObject *v) /* Advance left block/index pair */ leftindex++; if (leftindex == BLOCKLEN) { - assert (leftblock->rightlink != NULL); + if (leftblock->rightlink == NULL) /* can occur when i==n-1 */ + break; leftblock = leftblock->rightlink; leftindex = 0; } |