From d6e6f2d72434c1aaaf8619e629b1fbbdd9cb638f Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Sun, 7 Jan 2024 16:33:05 +0100 Subject: fix overwriting object keys removes the implicit call to json_detach (via json_delete), and sets the parent field on the src obj Signed-off-by: Anna (navi) Figueiredo Gomes --- src/internal.h | 8 -------- src/object.c | 10 ++++++++-- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/internal.h b/src/internal.h index 7ea8a5e..f1e08dc 100644 --- a/src/internal.h +++ b/src/internal.h @@ -56,14 +56,6 @@ inline static void add_children(struct json *dest, struct json *src) { src->parent = dest; } -inline static void adjust_pointers(struct json* from, struct json* to) { - to->prev = from->prev; - to->next = from->next; - if (from->prev) from->prev->next = to; - if (from->next) from->next->prev = to; -} - - enum json_parse_result parse_value(struct json **json_out, struct raw_json *raw, size_t depth); enum json_parse_result parse_object(struct json **json_out, struct raw_json *raw, size_t depth); enum json_parse_result parse_array(struct json **json_out, struct raw_json *raw, size_t depth); diff --git a/src/object.c b/src/object.c index b380008..7178bdd 100644 --- a/src/object.c +++ b/src/object.c @@ -27,9 +27,15 @@ void add_to_object(struct json *dest, char *key, struct json *src) { if (strcmp(e->key, key) == 0) { src->index = e->index; dest->children->items[i] = src; + src->parent = dest; - adjust_pointers(e, src); - json_delete(e); + src->prev = e->prev; + src->next = e->next; + if (e->prev) e->prev->next = src; + if (e->next) e->next->prev = src; + + json_clear(e); + free(e); return; } } -- cgit v1.2.3