]> granicus.if.org Git - python/commitdiff
Fix another case of potential signed overflow.
authorMark Dickinson <dickinsm@gmail.com>
Sun, 15 Nov 2009 12:56:08 +0000 (12:56 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 15 Nov 2009 12:56:08 +0000 (12:56 +0000)
Objects/rangeobject.c

index cabe785256846a8d707d7cb8485928ce4cf586f6..ec75c8fcfe11cd694b36b8f6e97d116cee3eff4e 100644 (file)
@@ -411,7 +411,10 @@ static PyObject *
 rangeiter_next(rangeiterobject *r)
 {
     if (r->index < r->len)
-        return PyLong_FromLong(r->start + (r->index++) * r->step);
+        /* cast to unsigned to avoid possible signed overflow 
+           in intermediate calculations. */
+        return PyLong_FromLong((long)(r->start +
+                                      (unsigned long)(r->index++) * r->step));
     return NULL;
 }