From b43dbc26f9abbd6bf96bd95e6701719575c57341 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sun, 15 Nov 2009 12:56:08 +0000 Subject: [PATCH] Fix another case of potential signed overflow. --- Objects/rangeobject.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index cabe7852568..ec75c8fcfe1 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -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; }