Allow evbuffer_ptr_set to yield a point just after the end of the buffer.

This commit is contained in:
Nick Mathewson 2011-06-06 21:03:35 -04:00
parent 8e2615421d
commit e6fe1da9ad
2 changed files with 8 additions and 1 deletions

View File

@ -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;
}
/**

View 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);