aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorallen <leloucharcher@163.com>2019-09-16 15:50:59 +0800
committerallen <leloucharcher@163.com>2019-09-16 15:50:59 +0800
commit53e9dd848f924021ec60ab3cd21c0c87c9dce37c (patch)
tree51e9942ba50729a7219bc7209b64226be09bc373 /src
parent63fb81faa55e131277a41e8dca5b2399c9f1709d (diff)
downloadjansson-53e9dd848f924021ec60ab3cd21c0c87c9dce37c.zip
jansson-53e9dd848f924021ec60ab3cd21c0c87c9dce37c.tar.gz
jansson-53e9dd848f924021ec60ab3cd21c0c87c9dce37c.tar.bz2
add the loop key length macro for circular reference detect
Diffstat (limited to 'src')
-rw-r--r--src/dump.c3
-rw-r--r--src/jansson_private.h2
-rw-r--r--src/value.c6
3 files changed, 6 insertions, 5 deletions
diff --git a/src/dump.c b/src/dump.c
index 5285d43..b57282f 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -296,8 +296,7 @@ static int do_dump(const json_t *json, size_t flags, int depth,
void *iter;
const char *separator;
int separator_length;
- /* Space for "0x", double the sizeof a pointer for the hex and a terminator. */
- char loop_key[2 + (sizeof(json) * 2) + 1];
+ char loop_key[LOOP_KEY_LEN];
if(flags & JSON_COMPACT) {
separator = ":";
diff --git a/src/jansson_private.h b/src/jansson_private.h
index 2da33d5..c7ce11a 100644
--- a/src/jansson_private.h
+++ b/src/jansson_private.h
@@ -91,6 +91,8 @@ char *jsonp_strdup(const char *str) JANSSON_ATTRS(warn_unused_result);
char *jsonp_strndup(const char *str, size_t len) JANSSON_ATTRS(warn_unused_result);
/* Circular reference check*/
+/* Space for "0x", double the sizeof a pointer for the hex and a terminator. */
+#define LOOP_KEY_LEN (2 + (sizeof(json_t *) * 2) + 1)
int jsonp_loop_check(hashtable_t *parents, const json_t *json, char *key, size_t key_size);
diff --git a/src/value.c b/src/value.c
index 9ec75ee..7a000f8 100644
--- a/src/value.c
+++ b/src/value.c
@@ -322,10 +322,10 @@ static json_t *json_object_deep_copy(const json_t *object, hashtable_t *parents)
{
json_t *result;
void *iter;
- char loop_key[2 + (sizeof(object) * 2) + 1];
+ char loop_key[LOOP_KEY_LEN];
if (jsonp_loop_check(parents, object, loop_key, sizeof(loop_key)))
- return NULL;
+ return NULL;
result = json_object();
if(!result)
@@ -641,7 +641,7 @@ static json_t *json_array_deep_copy(const json_t *array, hashtable_t *parents)
{
json_t *result;
size_t i;
- char loop_key[2 + (sizeof(array) * 2) + 1];
+ char loop_key[LOOP_KEY_LEN];
if (jsonp_loop_check(parents, array, loop_key, sizeof(loop_key)))
return NULL;