[pypy-svn] pypy bytearray: (mfoord) bytearray.insert index calculated correctly for out-of-bounds
mfoord
commits-noreply at bitbucket.org
Tue Jan 18 21:19:11 CET 2011
Author: Michael Foord <michael at voidspace.org.uk>
Branch: bytearray
Changeset: r40900:ab9098e19026
Date: 2011-01-18 21:11 +0100
http://bitbucket.org/pypy/pypy/changeset/ab9098e19026/
Log: (mfoord) bytearray.insert index calculated correctly for out-of-
bounds
diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -262,9 +262,16 @@
return W_BytearrayObject(newdata)
def bytearray_insert__Bytearray_Int_ANY(space, w_bytearray, w_idx, w_other):
- index = w_idx.intval
+ where = w_idx.intval
+ length = len(w_bytearray.data)
+ if where < 0:
+ where += length
+ if where < 0:
+ where = 0
+ elif where > length:
+ where = length
val = getbytevalue(space, w_other)
- w_bytearray.data.insert(index, val)
+ w_bytearray.data.insert(where, val)
return space.w_None
def bytearray_pop__Bytearray_Int(space, w_bytearray, w_idx):
More information about the Pypy-commit
mailing list