add the loop key length macro for circular reference detect
This commit is contained in:
parent
63fb81faa5
commit
53e9dd848f
@ -296,8 +296,7 @@ static int do_dump(const json_t *json, size_t flags, int depth,
|
|||||||
void *iter;
|
void *iter;
|
||||||
const char *separator;
|
const char *separator;
|
||||||
int separator_length;
|
int separator_length;
|
||||||
/* Space for "0x", double the sizeof a pointer for the hex and a terminator. */
|
char loop_key[LOOP_KEY_LEN];
|
||||||
char loop_key[2 + (sizeof(json) * 2) + 1];
|
|
||||||
|
|
||||||
if(flags & JSON_COMPACT) {
|
if(flags & JSON_COMPACT) {
|
||||||
separator = ":";
|
separator = ":";
|
||||||
|
@ -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);
|
char *jsonp_strndup(const char *str, size_t len) JANSSON_ATTRS(warn_unused_result);
|
||||||
|
|
||||||
/* Circular reference check*/
|
/* 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);
|
int jsonp_loop_check(hashtable_t *parents, const json_t *json, char *key, size_t key_size);
|
||||||
|
|
||||||
|
|
||||||
|
@ -322,10 +322,10 @@ static json_t *json_object_deep_copy(const json_t *object, hashtable_t *parents)
|
|||||||
{
|
{
|
||||||
json_t *result;
|
json_t *result;
|
||||||
void *iter;
|
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)))
|
if (jsonp_loop_check(parents, object, loop_key, sizeof(loop_key)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
result = json_object();
|
result = json_object();
|
||||||
if(!result)
|
if(!result)
|
||||||
@ -641,7 +641,7 @@ static json_t *json_array_deep_copy(const json_t *array, hashtable_t *parents)
|
|||||||
{
|
{
|
||||||
json_t *result;
|
json_t *result;
|
||||||
size_t i;
|
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)))
|
if (jsonp_loop_check(parents, array, loop_key, sizeof(loop_key)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user