|
|
|
@ -39,11 +39,9 @@ |
|
|
|
|
* don't have to. */ |
|
|
|
|
#define sscanf THINK_TWICE_ABOUT_USING_SSCANF |
|
|
|
|
|
|
|
|
|
#define STARTING_CAPACITY 15 |
|
|
|
|
#define ARRAY_MAX_CAPACITY 122880 /* 15*(2^13) */ |
|
|
|
|
#define OBJECT_MAX_CAPACITY 960 /* 15*(2^6) */ |
|
|
|
|
#define MAX_NESTING 2048 |
|
|
|
|
#define DOUBLE_SERIALIZATION_FORMAT "%f" |
|
|
|
|
#define STARTING_CAPACITY 16 |
|
|
|
|
#define MAX_NESTING 2048 |
|
|
|
|
#define FLOAT_FORMAT "%1.17g" |
|
|
|
|
|
|
|
|
|
#define SIZEOF_TOKEN(a) (sizeof(a) - 1) |
|
|
|
|
#define SKIP_CHAR(str) ((*str)++) |
|
|
|
@ -354,9 +352,6 @@ static JSON_Status json_object_add(JSON_Object *object, const char *name, JSON_V |
|
|
|
|
} |
|
|
|
|
if (object->count >= object->capacity) { |
|
|
|
|
size_t new_capacity = MAX(object->capacity * 2, STARTING_CAPACITY); |
|
|
|
|
if (new_capacity > OBJECT_MAX_CAPACITY) { |
|
|
|
|
return JSONFailure; |
|
|
|
|
} |
|
|
|
|
if (json_object_resize(object, new_capacity) == JSONFailure) { |
|
|
|
|
return JSONFailure; |
|
|
|
|
} |
|
|
|
@ -443,9 +438,6 @@ static JSON_Array * json_array_init(JSON_Value *wrapping_value) { |
|
|
|
|
static JSON_Status json_array_add(JSON_Array *array, JSON_Value *value) { |
|
|
|
|
if (array->count >= array->capacity) { |
|
|
|
|
size_t new_capacity = MAX(array->capacity * 2, STARTING_CAPACITY); |
|
|
|
|
if (new_capacity > ARRAY_MAX_CAPACITY) { |
|
|
|
|
return JSONFailure; |
|
|
|
|
} |
|
|
|
|
if (json_array_resize(array, new_capacity) == JSONFailure) { |
|
|
|
|
return JSONFailure; |
|
|
|
|
} |
|
|
|
@ -929,13 +921,7 @@ static int json_serialize_to_buffer_r(const JSON_Value *value, char *buf, int le |
|
|
|
|
if (buf != NULL) { |
|
|
|
|
num_buf = buf; |
|
|
|
|
} |
|
|
|
|
if (num == ((double)(int)num)) { /* check if num is integer */ |
|
|
|
|
written = sprintf(num_buf, "%d", (int)num); |
|
|
|
|
} else if (num == ((double)(unsigned int)num)) { |
|
|
|
|
written = sprintf(num_buf, "%u", (unsigned int)num); |
|
|
|
|
} else { |
|
|
|
|
written = sprintf(num_buf, DOUBLE_SERIALIZATION_FORMAT, num); |
|
|
|
|
} |
|
|
|
|
written = sprintf(num_buf, FLOAT_FORMAT, num); |
|
|
|
|
if (written < 0) { |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
@ -1315,8 +1301,12 @@ JSON_Value * json_value_init_string(const char *string) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JSON_Value * json_value_init_number(double number) { |
|
|
|
|
JSON_Value *new_value = (JSON_Value*)parson_malloc(sizeof(JSON_Value)); |
|
|
|
|
if (!new_value) { |
|
|
|
|
JSON_Value *new_value = NULL; |
|
|
|
|
if ((number * 0.0) != 0.0) { /* nan and inf test */ |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
new_value = (JSON_Value*)parson_malloc(sizeof(JSON_Value)); |
|
|
|
|
if (new_value == NULL) { |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
new_value->parent = NULL; |
|
|
|
|