diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-11-20 17:26:25 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-11-20 17:26:25 (GMT) |
commit | 5a1ca6e36802f48a6cbcbd563770427ded747e0f (patch) | |
tree | 4839f8d50529d34dde76dd22e9707884cf5b5968 /Modules/_io | |
parent | e062ba48b6945ed0fa8be65d26ddbf88374293c0 (diff) | |
download | cpython-5a1ca6e36802f48a6cbcbd563770427ded747e0f.zip cpython-5a1ca6e36802f48a6cbcbd563770427ded747e0f.tar.gz cpython-5a1ca6e36802f48a6cbcbd563770427ded747e0f.tar.bz2 |
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
........
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/bytesio.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index 29fb1ea..c8fb3eb 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -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); |