mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-08 03:44:22 -04:00
reintroduce a memmove when there is enough misalignment to hold the new data; otherwise the size of the buffer may grow without bounds
svn:r857
This commit is contained in:
parent
99a1063e73
commit
e711ce454a
16
buffer.c
16
buffer.c
@ -659,12 +659,24 @@ evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen)
|
||||
|
||||
remain = chain->buffer_len - chain->misalign - chain->off;
|
||||
if (remain >= datlen) {
|
||||
/*there's enough space to hold all the data in the current last chain*/
|
||||
/* there's enough space to hold all the data in the
|
||||
* current last chain */
|
||||
memcpy(chain->buffer + chain->misalign + chain->off,
|
||||
data, datlen);
|
||||
chain->off += datlen;
|
||||
buf->total_len += datlen;
|
||||
goto out;
|
||||
} else if (chain->misalign >= datlen) {
|
||||
/* we can fit the data into the misalignment */
|
||||
memmove(chain->buffer,
|
||||
chain->buffer + chain->misalign,
|
||||
chain->off);
|
||||
chain->misalign = 0;
|
||||
|
||||
memcpy(chain->buffer + chain->off, data, datlen);
|
||||
chain->off += datlen;
|
||||
buf->total_len += datlen;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* we need to add another chain */
|
||||
@ -678,7 +690,7 @@ evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen)
|
||||
buf->last = chain->next;
|
||||
buf->previous_to_last = chain;
|
||||
buf->total_len += datlen;
|
||||
|
||||
|
||||
memcpy(chain->buffer + chain->misalign + chain->off,
|
||||
data, remain);
|
||||
chain->off += remain;
|
||||
|
Loading…
x
Reference in New Issue
Block a user