]> granicus.if.org Git - python/commit
SF patch #103158 by Greg Ball: Don't do unsafe arithmetic in xrange
authorGuido van Rossum <guido@python.org>
Mon, 15 Jan 2001 18:58:56 +0000 (18:58 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 15 Jan 2001 18:58:56 +0000 (18:58 +0000)
commit65e0b99b611a42fd6548b2783a234f32630e6f1b
tree9f8c3f5ee6f625cb517cd5f95501adfd33d8ce20
parentafc4f0413ae7c307207772373937b0eb1e0a645b
SF patch #103158 by Greg Ball: Don't do unsafe arithmetic in xrange
object.

This fixes potential overflows in xrange()'s internal calculations on
64-bit platforms.  The fix is complicated because the sq_length slot
function can only return an int; we want to support
xrange(sys.maxint), which is a 64-bit quantity on most 64-bit
platforms (except Win64).  The solution is hacky but the best
possible: when the range is that long, we can use it in a for loop but
we can't ask for its length (nor can we actually iterate beyond
2**31-1, because the sq_item slot function has the same restrictions
on its arguments.  Fixing those restrictions is a project for another
day...
Objects/rangeobject.c