Skip to content

Commit

Permalink
Don't just keep on reading,
Browse files Browse the repository at this point in the history
stop when you get to the end
of the buffer, dummy.
  • Loading branch information
pramsey committed Nov 21, 2017
1 parent cf664b8 commit c211356
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,13 @@ http_writeback(void *contents, size_t size, size_t nmemb, void *userp)
static size_t
http_readback(void *buffer, size_t size, size_t nitems, void *instream)
{
size_t realsize = size * nitems;
size_t reqsize = size * nitems;
StringInfo si = (StringInfo)instream;
memcpy(buffer, si->data + si->cursor, realsize);
si->cursor += realsize;
return realsize;
size_t remaining = si->len - si->cursor;
size_t readsize = reqsize < remaining ? reqsize : remaining;
memcpy(buffer, si->data + si->cursor, readsize);
si->cursor += readsize;
return readsize;
}

static void
Expand Down

0 comments on commit c211356

Please sign in to comment.