aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2009-10-13 15:40:26 +0300
committerPetri Lehtinen <petri@digip.org>2009-10-13 15:40:26 +0300
commit185e107d24f24a4641d598722bc3f60eac10effc (patch)
tree1c8f15c129129f5cbc713f65cb9aa2bfcea81bfa
parentca7703fbd127a6279e9842a843f317a639db87e2 (diff)
downloadjansson-185e107d24f24a4641d598722bc3f60eac10effc.zip
jansson-185e107d24f24a4641d598722bc3f60eac10effc.tar.gz
jansson-185e107d24f24a4641d598722bc3f60eac10effc.tar.bz2
Don't use non-portable asprintf()
Thanks to Adam Strzelecki for reporting.
-rw-r--r--src/dump.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/dump.c b/src/dump.c
index 93717ab..dad64f8 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -13,6 +13,9 @@
#include <jansson.h>
#include "strbuffer.h"
+#define MAX_INTEGER_STR_LENGTH 100
+#define MAX_REAL_STR_LENGTH 100
+
typedef int (*dump_func)(const char *buffer, int size, void *data);
struct string
@@ -126,30 +129,26 @@ static int do_dump(const json_t *json, unsigned long flags, int depth,
case JSON_INTEGER:
{
- char *buffer;
- int size, ret;
+ char buffer[MAX_INTEGER_STR_LENGTH];
+ int size;
- size = asprintf(&buffer, "%d", json_integer_value(json));
- if(size == -1)
+ size = snprintf(buffer, MAX_INTEGER_STR_LENGTH, "%d", json_integer_value(json));
+ if(size >= MAX_INTEGER_STR_LENGTH)
return -1;
- ret = dump(buffer, size, data);
- free(buffer);
- return ret;
+ return dump(buffer, size, data);
}
case JSON_REAL:
{
- char *buffer;
- int size, ret;
+ char buffer[MAX_REAL_STR_LENGTH];
+ int size;
- size = asprintf(&buffer, "%.17f", json_real_value(json));
- if(size == -1)
+ size = snprintf(buffer, MAX_REAL_STR_LENGTH, "%0.17f", json_real_value(json));
+ if(size >= MAX_REAL_STR_LENGTH)
return -1;
- ret = dump(buffer, size, data);
- free(buffer);
- return ret;
+ return dump(buffer, size, data);
}
case JSON_STRING: