[gnutls-devel] [PATCH 4/6] Deduplicated some code in _gnutls_buffer_append_data().
Jaak Ristioja
jaak.ristioja at cyber.ee
Tue Dec 16 17:18:37 CET 2014
---
lib/gnutls_str.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/lib/gnutls_str.c b/lib/gnutls_str.c
index 9e36924..3cc7f7e 100644
--- a/lib/gnutls_str.c
+++ b/lib/gnutls_str.c
@@ -113,10 +113,9 @@ _gnutls_buffer_append_data(gnutls_buffer_st * dest, const void *data,
if (data_size == 0)
return 0;
+ size_t const unused = MEMSUB(dest->data, dest->allocd);
size_t const tot_len = data_size + dest->length;
if (dest->max_length >= tot_len) {
- size_t const unused = MEMSUB(dest->data, dest->allocd);
-
if (dest->max_length - unused <= tot_len) {
if (dest->length && dest->data)
memmove(dest->allocd, dest->data,
@@ -124,12 +123,7 @@ _gnutls_buffer_append_data(gnutls_buffer_st * dest, const void *data,
dest->data = dest->allocd;
}
- memcpy(&dest->data[dest->length], data, data_size);
- dest->length = tot_len;
-
- return tot_len;
} else {
- size_t const unused = MEMSUB(dest->data, dest->allocd);
size_t const new_len =
MAX(data_size, MIN_CHUNK) + MAX(dest->max_length,
MIN_CHUNK);
@@ -145,12 +139,10 @@ _gnutls_buffer_append_data(gnutls_buffer_st * dest, const void *data,
if (dest->length && dest->data)
memmove(dest->allocd, dest->data, dest->length);
dest->data = dest->allocd;
-
- memcpy(&dest->data[dest->length], data, data_size);
- dest->length = tot_len;
-
- return tot_len;
}
+ memcpy(&dest->data[dest->length], data, data_size);
+ dest->length = tot_len;
+ return tot_len;
}
int _gnutls_buffer_resize(gnutls_buffer_st * dest, size_t new_size)
--
2.2.0
More information about the Gnutls-devel
mailing list