From: niks Date: Fri, 16 Jul 2010 13:11:09 +0000 (-0400) Subject: Fix wrong sie calculation of iovec buffers when exact=1 X-Git-Tag: release-2.0.6-rc~28 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65abdc2011fe1019471cddff78d3cf596b2bccbe;p=libevent Fix wrong sie calculation of iovec buffers when exact=1 The old code had a bug where the 'exact' flag to 1 in _evbuffer_read_setup_vecs would never actually make the iov_len field of the last iovec get truncated. This patch fixes that. --- diff --git a/buffer.c b/buffer.c index 7b0262f3..2efd0125 100644 --- a/buffer.c +++ b/buffer.c @@ -1844,8 +1844,8 @@ _evbuffer_read_setup_vecs(struct evbuffer *buf, ev_ssize_t howmuch, chain = *firstchainp; for (i = 0; i < n_vecs_avail && so_far < howmuch; ++i) { size_t avail = CHAIN_SPACE_LEN(chain); - if (avail > howmuch && exact) - avail = howmuch; + if (avail > (howmuch - so_far) && exact) + avail = howmuch - so_far; vecs[i].iov_base = CHAIN_SPACE_PTR(chain); vecs[i].iov_len = avail; so_far += avail;