|
|
|
@ -11,6 +11,7 @@
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
#include <unistd.h> |
|
|
|
|
#include "jansson_private.h" |
|
|
|
|
#include "strbuffer.h" |
|
|
|
|
|
|
|
|
@ -74,6 +75,7 @@ int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size)
|
|
|
|
|
{ |
|
|
|
|
if(size >= strbuff->size - strbuff->length) |
|
|
|
|
{ |
|
|
|
|
int backoff = 1; |
|
|
|
|
size_t new_size; |
|
|
|
|
char *new_value; |
|
|
|
|
|
|
|
|
@ -86,9 +88,13 @@ int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size)
|
|
|
|
|
new_size = max(strbuff->size * STRBUFFER_FACTOR, |
|
|
|
|
strbuff->length + size + 1); |
|
|
|
|
|
|
|
|
|
while (42) { |
|
|
|
|
new_value = realloc(strbuff->value, new_size); |
|
|
|
|
if(!new_value) |
|
|
|
|
return -1; |
|
|
|
|
if (new_value) |
|
|
|
|
break; |
|
|
|
|
usleep(backoff * 1000); |
|
|
|
|
backoff <<= 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
strbuff->value = new_value; |
|
|
|
|
strbuff->size = new_size; |
|
|
|
|