Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch:
Changeset: r97471:6e25c50447f0
Date: 2019-09-13 11:21 +0200
http://bitbucket.org/pypy/pypy/changeset/6e25c50447f0/
Log: fix corner case about readline with limit that goes beyond the end
of the string
diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -429,10 +429,9 @@
assert 0 <= ord(marker) < 128
# ascii fast path
if self.ulen == len(self.text):
- if limit < 0:
- end = len(self.text)
- else:
- end = self.pos + limit
+ end = len(self.text)
+ if limit >= 0:
+ end = min(end, self.pos + limit)
pos = self.pos
assert pos >= 0
assert end >= 0
diff --git a/pypy/module/_io/test/test_interp_textio.py
b/pypy/module/_io/test/test_interp_textio.py
--- a/pypy/module/_io/test/test_interp_textio.py
+++ b/pypy/module/_io/test/test_interp_textio.py
@@ -35,6 +35,7 @@
@given(data=st_readline(),
mode=st.sampled_from(['\r', '\n', '\r\n', '']))
@settings(deadline=None, database=None)
+@example(data=(u'\n\r\n', [0, -1, 2, -1, 0, -1]), mode='\r')
def test_readline(space, data, mode):
txt, limits = data
w_stream = W_BytesIO(space)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit