Avoid problems with object's serial number growing too big
Transform serial key comparison from substraction to real comparison. Reset serial to zero in json_object_clear() to avoid it growing out of bounds when reusing objects. Closes GH-40. Closes GH-41.
This commit is contained in:
parent
5ec101ec21
commit
0f2cdd70ff
@ -159,8 +159,10 @@ static int object_key_compare_keys(const void *key1, const void *key2)
|
|||||||
|
|
||||||
static int object_key_compare_serials(const void *key1, const void *key2)
|
static int object_key_compare_serials(const void *key1, const void *key2)
|
||||||
{
|
{
|
||||||
return (*(const object_key_t **)key1)->serial -
|
size_t a = (*(const object_key_t **)key1)->serial;
|
||||||
(*(const object_key_t **)key2)->serial;
|
size_t b = (*(const object_key_t **)key2)->serial;
|
||||||
|
|
||||||
|
return a < b ? -1 : a == b ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_dump(const json_t *json, size_t flags, int depth,
|
static int do_dump(const json_t *json, size_t flags, int depth,
|
||||||
|
@ -186,7 +186,9 @@ int json_object_clear(json_t *json)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
object = json_to_object(json);
|
object = json_to_object(json);
|
||||||
|
|
||||||
hashtable_clear(&object->hashtable);
|
hashtable_clear(&object->hashtable);
|
||||||
|
object->serial = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user