]> granicus.if.org Git - python/commitdiff
Merged revisions 86587 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sat, 20 Nov 2010 17:26:25 +0000 (17:26 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 20 Nov 2010 17:26:25 +0000 (17:26 +0000)
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
........

Lib/test/test_memoryio.py
Misc/NEWS
Modules/_io/bytesio.c

index 89c8196676d840a8d1298c7be5e0fbd26472aff6..027ac9452d0aaa770fdfede6ad5f72d5361b4eae 100644 (file)
@@ -392,6 +392,11 @@ class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase):
         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")
index b51e6e67b11215e6a6919f232bb4b0e912ae50fe..7794521353a902faeab343248838929c4069155c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,11 @@ Library
 - 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 #1682942: configparser supports alternative option/value delimiters.
+
 Build
 -----
 
index 29fb1ead01882f408336b2e9a7435023c54c2933..c8fb3eb95f4bd160b1a057fbba1fba0a92e8507e 100644 (file)
@@ -391,15 +391,20 @@ static PyObject *
 bytesio_readinto(bytesio *self, PyObject *buffer)
 {
     void *raw_buffer;
-    Py_ssize_t len;
+    Py_ssize_t len, n;
 
     CHECK_CLOSED(self);
 
     if (PyObject_AsWriteBuffer(buffer, &raw_buffer, &len) == -1)
         return NULL;
 
-    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(raw_buffer, self->buf + self->pos, len);
     assert(self->pos + len < PY_SSIZE_T_MAX);