[Python-checkins] r83768 - python/branches/py3k/Objects/bytearrayobject.c

mark.dickinson python-checkins at python.org
Fri Aug 6 23:33:18 CEST 2010


Author: mark.dickinson
Date: Fri Aug  6 23:33:18 2010
New Revision: 83768

Log:
Issue #9530:  Fix a couple of places where undefined behaviour can
occur, as a result of signed integer overflow.


Modified:
   python/branches/py3k/Objects/bytearrayobject.c

Modified: python/branches/py3k/Objects/bytearrayobject.c
==============================================================================
--- python/branches/py3k/Objects/bytearrayobject.c	(original)
+++ python/branches/py3k/Objects/bytearrayobject.c	Fri Aug  6 23:33:18 2010
@@ -649,6 +649,11 @@
 
             if (!_canresize(self))
                 return -1;
+
+            if (slicelen == 0)
+                /* Nothing to do here. */
+                return 0;
+
             if (step < 0) {
                 stop = start + 1;
                 start = stop + step * (slicelen - 1) - 1;
@@ -665,7 +670,7 @@
                         self->ob_bytes + cur + 1, lim);
             }
             /* Move the tail of the bytes, in one chunk */
-            cur = start + slicelen*step;
+            cur = start + (size_t)slicelen*step;
             if (cur < (size_t)PyByteArray_GET_SIZE(self)) {
                 memmove(self->ob_bytes + cur - slicelen,
                         self->ob_bytes + cur,
@@ -679,7 +684,8 @@
         }
         else {
             /* Assign slice */
-            Py_ssize_t cur, i;
+            Py_ssize_t i;
+            size_t cur;
 
             if (needed != slicelen) {
                 PyErr_Format(PyExc_ValueError,


More information about the Python-checkins mailing list