|
|
@ -11,6 +11,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <string.h> |
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
#include <unistd.h> |
|
|
|
#include "jansson_private.h" |
|
|
|
#include "jansson_private.h" |
|
|
|
#include "strbuffer.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) |
|
|
|
if(size >= strbuff->size - strbuff->length) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
int backoff = 1; |
|
|
|
size_t new_size; |
|
|
|
size_t new_size; |
|
|
|
char *new_value; |
|
|
|
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, |
|
|
|
new_size = max(strbuff->size * STRBUFFER_FACTOR, |
|
|
|
strbuff->length + size + 1); |
|
|
|
strbuff->length + size + 1); |
|
|
|
|
|
|
|
|
|
|
|
new_value = realloc(strbuff->value, new_size); |
|
|
|
while (42) { |
|
|
|
if(!new_value) |
|
|
|
new_value = realloc(strbuff->value, new_size); |
|
|
|
return -1; |
|
|
|
if (new_value) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
usleep(backoff * 1000); |
|
|
|
|
|
|
|
backoff <<= 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
strbuff->value = new_value; |
|
|
|
strbuff->value = new_value; |
|
|
|
strbuff->size = new_size; |
|
|
|
strbuff->size = new_size; |
|
|
|