From: Jan Venekamp Date: Sun, 20 Nov 2022 01:08:25 +0000 (+0100) Subject: uci: maintain option position in uci_add_list X-Git-Url: http://git.openwrt.org/?p=project%2Fuci.git;a=commitdiff_plain;h=b2f341769d1dcd3e670d2462ec6a0de2bb756fee uci: maintain option position in uci_add_list Maintain the position of an option in the list when a string option is converted to a list option in uci_add_list. Signed-off-by: Jan Venekamp --- diff --git a/list.c b/list.c index 3518967..e6d631c 100644 --- a/list.c +++ b/list.c @@ -115,7 +115,7 @@ uci_free_option(struct uci_option *o) } static struct uci_option * -uci_alloc_list(struct uci_section *s, const char *name) +uci_alloc_list(struct uci_section *s, const char *name, struct uci_list *after) { struct uci_package *p = s->package; struct uci_context *ctx = p->ctx; @@ -125,7 +125,7 @@ uci_alloc_list(struct uci_section *s, const char *name) o->type = UCI_TYPE_LIST; o->section = s; uci_list_init(&o->v.list); - uci_list_add(&s->options, &o->e.list); + uci_list_insert(after ? after : s->options.prev, &o->e.list); return o; } @@ -628,7 +628,7 @@ int uci_add_list(struct uci_context *ctx, struct uci_ptr *ptr) if (!ptr->o) { /* create new list */ UCI_TRAP_SAVE(ctx, error); - ptr->o = uci_alloc_list(ptr->s, ptr->option); + ptr->o = uci_alloc_list(ptr->s, ptr->option, NULL); UCI_TRAP_RESTORE(ctx); ptr->last = &ptr->o->e; } else if (ptr->o->type == UCI_TYPE_STRING) { @@ -636,7 +636,7 @@ int uci_add_list(struct uci_context *ctx, struct uci_ptr *ptr) struct uci_option *old = ptr->o; UCI_TRAP_SAVE(ctx, error); e2 = uci_alloc_generic(ctx, UCI_TYPE_ITEM, old->v.string, sizeof(struct uci_option)); - ptr->o = uci_alloc_list(ptr->s, ptr->option); + ptr->o = uci_alloc_list(ptr->s, ptr->option, &old->e.list); UCI_TRAP_RESTORE(ctx); uci_list_add(&ptr->o->v.list, &e2->list);