mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-29 01:03:57 +03:00
buffer: Apply coding style to realloc_buffer()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
60
src/buffer.c
60
src/buffer.c
@@ -127,38 +127,38 @@ void ssh_buffer_set_secure(ssh_buffer buffer){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int realloc_buffer(struct ssh_buffer_struct *buffer, size_t needed) {
|
static int realloc_buffer(struct ssh_buffer_struct *buffer, size_t needed) {
|
||||||
size_t smallest = 1;
|
size_t smallest = 1;
|
||||||
char *new;
|
char *new;
|
||||||
|
|
||||||
buffer_verify(buffer);
|
buffer_verify(buffer);
|
||||||
|
|
||||||
/* Find the smallest power of two which is greater or equal to needed */
|
/* Find the smallest power of two which is greater or equal to needed */
|
||||||
while(smallest <= needed) {
|
while(smallest <= needed) {
|
||||||
if (smallest == 0) {
|
if (smallest == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
smallest <<= 1;
|
smallest <<= 1;
|
||||||
}
|
}
|
||||||
needed = smallest;
|
needed = smallest;
|
||||||
if (buffer->secure){
|
if (buffer->secure){
|
||||||
new = malloc(needed);
|
new = malloc(needed);
|
||||||
if (new == NULL) {
|
if (new == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(new, buffer->data,buffer->used);
|
memcpy(new, buffer->data,buffer->used);
|
||||||
explicit_bzero(buffer->data, buffer->used);
|
explicit_bzero(buffer->data, buffer->used);
|
||||||
SAFE_FREE(buffer->data);
|
SAFE_FREE(buffer->data);
|
||||||
} else {
|
} else {
|
||||||
new = realloc(buffer->data, needed);
|
new = realloc(buffer->data, needed);
|
||||||
if (new == NULL) {
|
if (new == NULL) {
|
||||||
buffer->data = NULL;
|
buffer->data = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer->data = new;
|
buffer->data = new;
|
||||||
buffer->allocated = needed;
|
buffer->allocated = needed;
|
||||||
buffer_verify(buffer);
|
buffer_verify(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal
|
/** @internal
|
||||||
|
|||||||
Reference in New Issue
Block a user