[Python-checkins] r86587 - in python/branches/py3k: Lib/test/test_memoryio.py Misc/NEWS Modules/_io/bytesio.c
benjamin.peterson
python-checkins at python.org
Sat Nov 20 18:24:04 CET 2010
Author: benjamin.peterson
Date: Sat Nov 20 18:24:04 2010
New Revision: 86587
Log:
correct logic when pos is after the string #10467
Modified:
python/branches/py3k/Lib/test/test_memoryio.py
python/branches/py3k/Misc/NEWS
python/branches/py3k/Modules/_io/bytesio.c
Modified: python/branches/py3k/Lib/test/test_memoryio.py
==============================================================================
--- python/branches/py3k/Lib/test/test_memoryio.py (original)
+++ python/branches/py3k/Lib/test/test_memoryio.py Sat Nov 20 18:24:04 2010
@@ -452,6 +452,11 @@
self.assertEqual(a.tobytes(), 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/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Sat Nov 20 18:24:04 2010
@@ -24,6 +24,9 @@
Library
-------
+- Issue #10467: Fix BytesIO.readinto() after seeking into a position after the
+ end of the file.
+
- Issue #1682942: configparser supports alternative option/value delimiters.
- Issue #5412: configparser supports mapping protocol access.
Modified: python/branches/py3k/Modules/_io/bytesio.c
==============================================================================
--- python/branches/py3k/Modules/_io/bytesio.c (original)
+++ python/branches/py3k/Modules/_io/bytesio.c Sat Nov 20 18:24:04 2010
@@ -430,15 +430,20 @@
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);
More information about the Python-checkins
mailing list