mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Allow evbuffer_ptr_set to yield a point just after the end of the buffer.
This commit is contained in:
parent
8e2615421d
commit
e6fe1da9ad
7
buffer.c
7
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user