]> granicus.if.org Git - libevent/commitdiff
Allow evbuffer_ptr_set to yield a point just after the end of the buffer.
authorNick Mathewson <nickm@torproject.org>
Tue, 7 Jun 2011 01:03:35 +0000 (21:03 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 13 Jun 2011 20:48:02 +0000 (16:48 -0400)
buffer.c
test/regress_buffer.c

index 84d3aea854b53e37e5e0e78ab31a8a845a2ee884..c4297ed05655e3bf325573af15d912a55635f364 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -2307,6 +2307,7 @@ evbuffer_ptr_set(struct evbuffer *buf, struct evbuffer_ptr *pos,
 {
        size_t left = position;
        struct evbuffer_chain *chain = NULL;
+       int result = 0;
 
        EVBUFFER_LOCK(buf);
 
@@ -2333,14 +2334,18 @@ evbuffer_ptr_set(struct evbuffer *buf, struct evbuffer_ptr *pos,
        if (chain) {
                pos->_internal.chain = chain;
                pos->_internal.pos_in_chain = position + left;
+       } else if (left == 0 && buf->last) {
+               pos->_internal.chain = buf->last;
+               pos->_internal.pos_in_chain = buf->last->off;
        } else {
                pos->_internal.chain = NULL;
                pos->pos = -1;
+               result = -1;
        }
 
        EVBUFFER_UNLOCK(buf);
 
-       return chain != NULL ? 0 : -1;
+       return result;
 }
 
 /**
index 2e5efeb150642dbf5b447abe5ff7b7b2956680bc..a9a4f6a3df9815976b17d0e26e9e296a5276dc52 100644 (file)
@@ -1222,6 +1222,8 @@ test_evbuffer_ptr_set(void *ptr)
        tt_assert(pos.pos == 10000);
        tt_assert(evbuffer_ptr_set(buf, &pos, 1000, EVBUFFER_PTR_ADD) == 0);
        tt_assert(pos.pos == 11000);
+       tt_assert(evbuffer_ptr_set(buf, &pos, 1000, EVBUFFER_PTR_ADD) == 0);
+       tt_assert(pos.pos == 12000);
        tt_assert(evbuffer_ptr_set(buf, &pos, 1000, EVBUFFER_PTR_ADD) == -1);
        tt_assert(pos.pos == -1);