From 10b3ebbe61a7031a3dae97f05834442220447181 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 3 Jun 2020 10:10:11 +0200 Subject: [PATCH] buffer: Reformat ssh_buffer_add_data() Signed-off-by: Andreas Schneider Reviewed-by: Anderson Toshiyuki Sasaki Reviewed-by: Jakub Jelen --- src/buffer.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index a2e6246a..476bc135 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -299,28 +299,29 @@ int ssh_buffer_reinit(struct ssh_buffer_struct *buffer) */ int ssh_buffer_add_data(struct ssh_buffer_struct *buffer, const void *data, uint32_t len) { - buffer_verify(buffer); + buffer_verify(buffer); - if (data == NULL) { - return -1; - } - - if (buffer->used + len < len) { - return -1; - } - - if (buffer->allocated < (buffer->used + len)) { - if(buffer->pos > 0) - buffer_shift(buffer); - if (realloc_buffer(buffer, buffer->used + len) < 0) { - return -1; + if (data == NULL) { + return -1; } - } - memcpy(buffer->data+buffer->used, data, len); - buffer->used+=len; - buffer_verify(buffer); - return 0; + if (buffer->used + len < len) { + return -1; + } + + if (buffer->allocated < (buffer->used + len)) { + if (buffer->pos > 0) { + buffer_shift(buffer); + } + if (realloc_buffer(buffer, buffer->used + len) < 0) { + return -1; + } + } + + memcpy(buffer->data + buffer->used, data, len); + buffer->used += len; + buffer_verify(buffer); + return 0; } /**