From a473b9da152d4cdd10eccc6d8eafa2b519da121d Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 28 Feb 2015 17:49:47 -0800 Subject: [PATCH] Use unsigned division and modulo for item assignment as well. --- Modules/_collectionsmodule.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index d12f0e8769e..908cfd2f3e1 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -780,7 +780,6 @@ deque_item(dequeobject *deque, Py_ssize_t i) b = deque->rightblock; } else { i += deque->leftindex; - assert(i >= 0); n = (Py_ssize_t)((unsigned) i / BLOCKLEN); i = (Py_ssize_t)((unsigned) i % BLOCKLEN); if (index < (Py_SIZE(deque) >> 1)) { @@ -840,14 +839,16 @@ deque_ass_item(dequeobject *deque, Py_ssize_t i, PyObject *v) return deque_del_item(deque, i); i += deque->leftindex; - n = i / BLOCKLEN; - i %= BLOCKLEN; + n = (Py_ssize_t)((unsigned) i / BLOCKLEN); + i = (Py_ssize_t)((unsigned) i % BLOCKLEN); if (index <= halflen) { b = deque->leftblock; while (n--) b = b->rightlink; } else { - n = (deque->leftindex + len - 1) / BLOCKLEN - n; + n = (Py_ssize_t)( + ((unsigned)(deque->leftindex + Py_SIZE(deque) - 1)) + / BLOCKLEN - n); b = deque->rightblock; while (n--) b = b->leftlink;