]> granicus.if.org Git - python/commitdiff
Issue #23553: Use an unsigned cast to tighten-up the bounds checking logic.
authorRaymond Hettinger <python@rcn.com>
Sun, 1 Mar 2015 08:38:00 +0000 (00:38 -0800)
committerRaymond Hettinger <python@rcn.com>
Sun, 1 Mar 2015 08:38:00 +0000 (00:38 -0800)
Modules/_collectionsmodule.c

index 0ca9be1df5bab018b13f25ff06a200a827b57a0d..69814bb34c5d4633d8f7abdfe5e6270accf6b3c6 100644 (file)
@@ -772,7 +772,7 @@ deque_item(dequeobject *deque, Py_ssize_t i)
     PyObject *item;
     Py_ssize_t n, index=i;
 
-    if (i < 0 || i >= Py_SIZE(deque)) {
+    if ((size_t)i >= (size_t)Py_SIZE(deque)) {
         PyErr_SetString(PyExc_IndexError,
                         "deque index out of range");
         return NULL;
@@ -836,7 +836,7 @@ deque_ass_item(dequeobject *deque, Py_ssize_t i, PyObject *v)
     block *b;
     Py_ssize_t n, len=Py_SIZE(deque), halflen=(len+1)>>1, index=i;
 
-    if (i < 0 || i >= len) {
+    if ((size_t)i >= (size_t)len) {
         PyErr_SetString(PyExc_IndexError,
                         "deque index out of range");
         return -1;