]> granicus.if.org Git - python/commitdiff
Issue #9530: Fix a couple of places where undefined behaviour can
authorMark Dickinson <dickinsm@gmail.com>
Fri, 6 Aug 2010 21:33:18 +0000 (21:33 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Fri, 6 Aug 2010 21:33:18 +0000 (21:33 +0000)
occur, as a result of signed integer overflow.

Objects/bytearrayobject.c

index 021ab1a5310de2e386ea4ea6aa223371353643e9..33f80d56f558105f97ee71373ed1b3c1c86480ab 100644 (file)
@@ -649,6 +649,11 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu
 
             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 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu
                         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 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu
         }
         else {
             /* Assign slice */
-            Py_ssize_t cur, i;
+            Py_ssize_t i;
+            size_t cur;
 
             if (needed != slicelen) {
                 PyErr_Format(PyExc_ValueError,