Skip to content

Commit

Permalink
Fix copy/append of the internal USERDATA objects
Browse files Browse the repository at this point in the history
Issue: #301
Closes: #301
  • Loading branch information
vstakhov committed Apr 24, 2024
1 parent 37edb29 commit 084de92
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/ucl_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -3391,10 +3391,20 @@ ucl_elt_append (ucl_object_t *head, ucl_object_t *elt)
head = elt;
}
else {
elt->prev = head->prev;
head->prev->next = elt;
head->prev = elt;
elt->next = NULL;
if (head->type == UCL_USERDATA) {
/* Userdata objects are VERY special! */
struct ucl_object_userdata *ud = (struct ucl_object_userdata *)head;
elt->prev = ud->obj.prev;
ud->obj.prev->next = elt;
ud->obj.prev = elt;
elt->next = NULL;
}
else {
elt->prev = head->prev;
head->prev->next = elt;
head->prev = elt;
elt->next = NULL;
}
}

return head;
Expand Down Expand Up @@ -3604,11 +3614,15 @@ ucl_object_copy_internal (const ucl_object_t *other, bool allow_array)
ucl_object_t *new;
ucl_object_iter_t it = NULL;
const ucl_object_t *cur;
size_t sz = sizeof(*new);

new = malloc (sizeof (*new));
if (other->type == UCL_USERDATA) {
sz = sizeof (struct ucl_object_userdata);
}
new = malloc (sz);

if (new != NULL) {
memcpy (new, other, sizeof (*new));
memcpy (new, other, sz);
if (other->flags & UCL_OBJECT_EPHEMERAL) {
/* Copied object is always non ephemeral */
new->flags &= ~UCL_OBJECT_EPHEMERAL;
Expand Down

0 comments on commit 084de92

Please sign in to comment.