summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-03-01 01:49:47 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-03-01 01:49:47 (GMT)
commita473b9da152d4cdd10eccc6d8eafa2b519da121d (patch)
tree20c396b421b7935e533bd42bac732c3a02e31be1
parent1c205518a35939ef555c74d0e2f8954a5e1828e1 (diff)
downloadcpython-a473b9da152d4cdd10eccc6d8eafa2b519da121d.zip
cpython-a473b9da152d4cdd10eccc6d8eafa2b519da121d.tar.gz
cpython-a473b9da152d4cdd10eccc6d8eafa2b519da121d.tar.bz2
Use unsigned division and modulo for item assignment as well.
-rw-r--r--Modules/_collectionsmodule.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index d12f0e876..908cfd2 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;