[pypy-svn] pypy default: Fix a crash in io.StringIO.read()
amauryfa
commits-noreply at bitbucket.org
Tue Jan 18 09:35:34 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r40828:401d6c31d374
Date: 2011-01-18 08:40 +0100
http://bitbucket.org/pypy/pypy/changeset/401d6c31d374/
Log: Fix a crash in io.StringIO.read()
diff --git a/pypy/module/_io/test/test_stringio.py b/pypy/module/_io/test/test_stringio.py
--- a/pypy/module/_io/test/test_stringio.py
+++ b/pypy/module/_io/test/test_stringio.py
@@ -22,3 +22,14 @@
sio.close()
raises(ValueError, sio.read, 1)
raises(ValueError, sio.write, u"text")
+
+ def testRead(self):
+ import io
+ buf = u"1234567890"
+ sio = io.StringIO(buf)
+
+ assert buf[:1] == sio.read(1)
+ assert buf[1:5] == sio.read(4)
+ assert buf[5:] == sio.read(900)
+ assert u"" == sio.read()
+
diff --git a/pypy/module/_io/interp_stringio.py b/pypy/module/_io/interp_stringio.py
--- a/pypy/module/_io/interp_stringio.py
+++ b/pypy/module/_io/interp_stringio.py
@@ -65,10 +65,12 @@
self._check_closed(space)
size = convert_size(space, w_size)
start = self.pos
- if size >= 0:
+ available = len(self.buf) - start
+ if size >= 0 and size <= available:
end = start + size
else:
end = len(self.buf)
+ assert 0 <= start <= end
self.pos = end
return space.wrap(u''.join(self.buf[start:end]))
More information about the Pypy-commit
mailing list