Kaydet (Commit) 4fec9ce6 authored tarafından Benjamin Peterson's avatar Benjamin Peterson

Merged revisions 86587 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r86587 | benjamin.peterson | 2010-11-20 11:24:04 -0600 (Sat, 20 Nov 2010) | 1 line

  correct logic when pos is after the string #10467
........
üst a731bf17
...@@ -438,6 +438,11 @@ class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase): ...@@ -438,6 +438,11 @@ class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase):
self.assertEqual(a.tostring(), b"1234567890d") self.assertEqual(a.tostring(), b"1234567890d")
memio.close() memio.close()
self.assertRaises(ValueError, memio.readinto, b) self.assertRaises(ValueError, memio.readinto, b)
memio = self.ioclass(b"123")
b = bytearray()
memio.seek(42)
memio.readinto(b)
self.assertEqual(b, b"")
def test_relative_seek(self): def test_relative_seek(self):
buf = self.buftype("1234567890") buf = self.buftype("1234567890")
......
...@@ -16,6 +16,9 @@ Library ...@@ -16,6 +16,9 @@ Library
- Issue #10198: fix duplicate header written to wave files when writeframes() - Issue #10198: fix duplicate header written to wave files when writeframes()
is called without data. is called without data.
- Issue #10467: Fix BytesIO.readinto() after seeking into a position after the
end of the file.
- Issue #5111: IPv6 Host in the Header is wrapped inside [ ]. Patch by Chandru. - Issue #5111: IPv6 Host in the Header is wrapped inside [ ]. Patch by Chandru.
Build Build
......
...@@ -391,7 +391,7 @@ static PyObject * ...@@ -391,7 +391,7 @@ static PyObject *
bytesio_readinto(bytesio *self, PyObject *args) bytesio_readinto(bytesio *self, PyObject *args)
{ {
Py_buffer buf; Py_buffer buf;
Py_ssize_t len; Py_ssize_t len, n;
CHECK_CLOSED(self); CHECK_CLOSED(self);
...@@ -399,8 +399,13 @@ bytesio_readinto(bytesio *self, PyObject *args) ...@@ -399,8 +399,13 @@ bytesio_readinto(bytesio *self, PyObject *args)
return NULL; return NULL;
len = buf.len; len = buf.len;
if (self->pos + len > self->string_size) /* adjust invalid sizes */
len = self->string_size - self->pos; n = self->string_size - self->pos;
if (len > n) {
len = n;
if (len < 0)
len = 0;
}
memcpy(buf.buf, self->buf + self->pos, len); memcpy(buf.buf, self->buf + self->pos, len);
assert(self->pos + len < PY_SSIZE_T_MAX); assert(self->pos + len < PY_SSIZE_T_MAX);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment