summaryrefslogtreecommitdiffstats
path: root/Modules/_io/bytesio.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-11-20 17:24:04 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-11-20 17:24:04 (GMT)
commitfa73555cfc414baff62ed41e0c8c2c85b167495a (patch)
treefd4efeef1167a060ecad62f74fc45260a5d19239 /Modules/_io/bytesio.c
parent6bcfadec07e1ac901f7ea3777db623731c4e6f58 (diff)
downloadcpython-fa73555cfc414baff62ed41e0c8c2c85b167495a.zip
cpython-fa73555cfc414baff62ed41e0c8c2c85b167495a.tar.gz
cpython-fa73555cfc414baff62ed41e0c8c2c85b167495a.tar.bz2
correct logic when pos is after the string #10467
Diffstat (limited to 'Modules/_io/bytesio.c')
-rw-r--r--Modules/_io/bytesio.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index c565404..b40513f 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -430,15 +430,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);