From 599292650c644793b73e21ba79ed706dbbd8b23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Sat, 22 Jun 2013 21:24:17 +0200 Subject: [PATCH] Buffer might already be full when chunker_fill is called. --- darc/_chunker.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/darc/_chunker.c b/darc/_chunker.c index 470025b8d..5492e8e55 100644 --- a/darc/_chunker.c +++ b/darc/_chunker.c @@ -116,17 +116,19 @@ chunker_free(Chunker *c) static int chunker_fill(Chunker *c) { + size_t n; memmove(c->data, c->data + c->last, c->position + c->remaining - c->last); c->position -= c->last; c->last = 0; - if(c->eof) { + n = c->buf_size - c->position - c->remaining; + if(c->eof || n == 0) { return 1; } - PyObject *data = PyObject_CallMethod(c->fd, "read", "i", c->buf_size - c->position - c->remaining); + PyObject *data = PyObject_CallMethod(c->fd, "read", "i", n); if(!data) { return 0; } - int n = PyBytes_Size(data); + n = PyBytes_Size(data); if(n) { memcpy(c->data + c->position + c->remaining, PyBytes_AsString(data), n); c->remaining += n;