[Python-checkins] cpython: Issue #23553: Use an unsigned cast to tighten-up the bounds checking logic.

raymond.hettinger python-checkins at python.org
Sun Mar 1 09:38:06 CET 2015


https://hg.python.org/cpython/rev/1e89094998b2
changeset:   94798:1e89094998b2
user:        Raymond Hettinger <python at rcn.com>
date:        Sun Mar 01 00:38:00 2015 -0800
summary:
  Issue #23553:  Use an unsigned cast to tighten-up the bounds checking logic.

files:
  Modules/_collectionsmodule.c |  4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)


diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -772,7 +772,7 @@
     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 @@
     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;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list