[Python-checkins] r86589 - in python/branches/release27-maint: Lib/test/test_memoryio.py Misc/NEWS Modules/_io/bytesio.c

benjamin.peterson python-checkins at python.org
Sat Nov 20 18:31:08 CET 2010


Author: benjamin.peterson
Date: Sat Nov 20 18:31:08 2010
New Revision: 86589

Log:
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
........


Modified:
   python/branches/release27-maint/   (props changed)
   python/branches/release27-maint/Lib/test/test_memoryio.py
   python/branches/release27-maint/Misc/NEWS
   python/branches/release27-maint/Modules/_io/bytesio.c

Modified: python/branches/release27-maint/Lib/test/test_memoryio.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_memoryio.py	(original)
+++ python/branches/release27-maint/Lib/test/test_memoryio.py	Sat Nov 20 18:31:08 2010
@@ -438,6 +438,11 @@
         self.assertEqual(a.tostring(), b"1234567890d")
         memio.close()
         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):
         buf = self.buftype("1234567890")

Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS	(original)
+++ python/branches/release27-maint/Misc/NEWS	Sat Nov 20 18:31:08 2010
@@ -16,6 +16,9 @@
 - Issue #10198: fix duplicate header written to wave files when writeframes()
   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.
 
 Build

Modified: python/branches/release27-maint/Modules/_io/bytesio.c
==============================================================================
--- python/branches/release27-maint/Modules/_io/bytesio.c	(original)
+++ python/branches/release27-maint/Modules/_io/bytesio.c	Sat Nov 20 18:31:08 2010
@@ -391,7 +391,7 @@
 bytesio_readinto(bytesio *self, PyObject *args)
 {
     Py_buffer buf;
-    Py_ssize_t len;
+    Py_ssize_t len, n;
 
     CHECK_CLOSED(self);
 
@@ -399,8 +399,13 @@
         return NULL;
 
     len = buf.len;
-    if (self->pos + len > self->string_size)
-        len = self->string_size - self->pos;
+    /* adjust invalid sizes */
+    n = self->string_size - self->pos;
+    if (len > n) {
+        len = n;
+        if (len < 0)
+            len = 0;
+    }
 
     memcpy(buf.buf, self->buf + self->pos, len);
     assert(self->pos + len < PY_SSIZE_T_MAX);


More information about the Python-checkins mailing list