[gnutls-devel] [PATCH 3/4] Deduplicated some code in _gnutls_buffer_append_data().

Jaak Ristioja jaak.ristioja at cyber.ee
Wed Dec 17 12:55:09 CET 2014


Signed-off-by: Jaak Ristioja <jaak.ristioja at cyber.ee>
---
 lib/gnutls_str.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/lib/gnutls_str.c b/lib/gnutls_str.c
index 6cfbbb6..267b813 100644
--- a/lib/gnutls_str.c
+++ b/lib/gnutls_str.c
@@ -120,15 +120,13 @@ _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) {
 			align_allocd_with_data(dest);
 		}
 	} 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);
@@ -141,9 +139,7 @@ _gnutls_buffer_append_data(gnutls_buffer_st * dest, const void *data,
 		dest->max_length = new_len;
 		dest->data = dest->allocd + unused;
 
-		if (dest->length && dest->data)
-			memmove(dest->allocd, dest->data, dest->length);
-		dest->data = dest->allocd;
+		align_allocd_with_data(dest);
 	}
 
 	memcpy(&dest->data[dest->length], data, data_size);
-- 
2.2.0




More information about the Gnutls-devel mailing list