Buffer might already be full when chunker_fill is called.

This commit is contained in:
Jonas Borgström 2013-06-22 21:24:17 +02:00
parent 8cc92d896d
commit 599292650c
1 changed files with 5 additions and 3 deletions

View File

@ -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;