summaryrefslogtreecommitdiff
path: root/src/openvpn/buffer.c
diff options
context:
space:
mode:
authorBernhard Schmidt <berni@debian.org>2019-02-20 14:11:51 +0100
committerBernhard Schmidt <berni@debian.org>2019-02-20 14:11:51 +0100
commit39ddb9cc8281bd239b94a3023da6329edb6718c1 (patch)
treedc6a8e7f1018f59f088c5b06b48eb24efe17f22d /src/openvpn/buffer.c
parentd5078cc44b8919a25cb7507e9e6da1d66f25bb5b (diff)
parent87356242baf10c8b2a94d9013e436ed2a0dada53 (diff)
Update upstream source from tag 'upstream/2.4.7'
Update to upstream version '2.4.7' with Debian dir d01da6ef78dc8ce91265e8f319468f6c34d23af8
Diffstat (limited to 'src/openvpn/buffer.c')
-rw-r--r--src/openvpn/buffer.c71
1 files changed, 33 insertions, 38 deletions
diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c
index f2ab066..f9c76b1 100644
--- a/src/openvpn/buffer.c
+++ b/src/openvpn/buffer.c
@@ -1234,49 +1234,44 @@ void
buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max_len,
const char *sep)
{
- int sep_len = strlen(sep);
+ const int sep_len = strlen(sep);
+ struct buffer_entry *more = bl->head;
+ size_t size = 0;
+ int count = 0;
+ for (count = 0; more; ++count)
+ {
+ size_t extra_len = BLEN(&more->buf) + sep_len;
+ if (size + extra_len > max_len)
+ {
+ break;
+ }
+
+ size += extra_len;
+ more = more->next;
+ }
- if (bl->head)
+ if (count >= 2)
{
- struct buffer_entry *more = bl->head;
- size_t size = 0;
- int count = 0;
- for (count = 0; more; ++count)
- {
- size_t extra_len = BLEN(&more->buf) + sep_len;
- if (size + extra_len > max_len)
- {
- break;
- }
+ struct buffer_entry *f;
+ ALLOC_OBJ_CLEAR(f, struct buffer_entry);
+ f->buf = alloc_buf(size + 1); /* prevent 0-byte malloc */
- size += extra_len;
- more = more->next;
+ struct buffer_entry *e = bl->head;
+ for (size_t i = 0; e && i < count; ++i)
+ {
+ struct buffer_entry *next = e->next;
+ buf_copy(&f->buf, &e->buf);
+ buf_write(&f->buf, sep, sep_len);
+ free_buf(&e->buf);
+ free(e);
+ e = next;
}
-
- if (count >= 2)
+ bl->head = f;
+ bl->size -= count - 1;
+ f->next = more;
+ if (!more)
{
- int i;
- struct buffer_entry *e = bl->head, *f;
-
- ALLOC_OBJ_CLEAR(f, struct buffer_entry);
- f->buf = alloc_buf(size + 1); /* prevent 0-byte malloc */
- f->buf.capacity = size;
- for (i = 0; e && i < count; ++i)
- {
- struct buffer_entry *next = e->next;
- buf_copy(&f->buf, &e->buf);
- buf_write(&f->buf, sep, sep_len);
- free_buf(&e->buf);
- free(e);
- e = next;
- }
- bl->head = f;
- bl->size -= count - 1;
- f->next = more;
- if (!more)
- {
- bl->tail = f;
- }
+ bl->tail = f;
}
}
}