Using smaller buffer size for number serialization.

Issue #88 and #61
pull/105/head
Krzysztof Gabis 6 years ago
parent 387c5665f6
commit 921da6f5d7
  1. 8
      parson.c

@ -41,7 +41,9 @@
#define STARTING_CAPACITY 16
#define MAX_NESTING 2048
#define FLOAT_FORMAT "%1.17g"
#define FLOAT_FORMAT "%1.17g" /* do not increase precision without incresing NUM_BUF_SIZE */
#define NUM_BUF_SIZE 64 /* double printed with "%1.17g" shouldn't be longer than 25 bytes so let's be paranoid and use 64 */
#define SIZEOF_TOKEN(a) (sizeof(a) - 1)
#define SKIP_CHAR(str) ((*str)++)
@ -1416,7 +1418,7 @@ JSON_Value * json_value_deep_copy(const JSON_Value *value) {
}
size_t json_serialization_size(const JSON_Value *value) {
char num_buf[1100]; /* recursively allocating buffer on stack is a bad idea, so let's do it only once */
char num_buf[NUM_BUF_SIZE]; /* recursively allocating buffer on stack is a bad idea, so let's do it only once */
int res = json_serialize_to_buffer_r(value, NULL, 0, 0, num_buf);
return res < 0 ? 0 : (size_t)(res + 1);
}
@ -1476,7 +1478,7 @@ char * json_serialize_to_string(const JSON_Value *value) {
}
size_t json_serialization_size_pretty(const JSON_Value *value) {
char num_buf[1100]; /* recursively allocating buffer on stack is a bad idea, so let's do it only once */
char num_buf[NUM_BUF_SIZE]; /* recursively allocating buffer on stack is a bad idea, so let's do it only once */
int res = json_serialize_to_buffer_r(value, NULL, 0, 1, num_buf);
return res < 0 ? 0 : (size_t)(res + 1);
}

Loading…
Cancel
Save