* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * GNU Lesser General Public License for more details.
*/
static void uci_list_set_pos(struct uci_list *head, struct uci_list *ptr, int pos)
uci_list_del(ptr);
uci_foreach_element(head, p) {
- new_head = &p->list;
if (pos-- <= 0)
break;
+ new_head = &p->list;
}
- uci_list_add(new_head, ptr);
+
+ uci_list_add(new_head->next, ptr);
}
static inline void uci_list_fixup(struct uci_list *ptr)
int uci_rename(struct uci_context *ctx, struct uci_ptr *ptr)
{
/* NB: UCI_INTERNAL use means without delta tracking */
- bool internal = ctx->internal;
+ bool internal = ctx && ctx->internal;
struct uci_element *e;
struct uci_package *p;
char *n;
int uci_add_section(struct uci_context *ctx, struct uci_package *p, const char *type, struct uci_section **res)
{
- bool internal = ctx->internal;
+ bool internal = ctx && ctx->internal;
struct uci_section *s;
UCI_HANDLE_ERR(ctx);
int uci_delete(struct uci_context *ctx, struct uci_ptr *ptr)
{
/* NB: pass on internal flag to uci_del_element */
- bool internal = ctx->internal;
+ bool internal = ctx && ctx->internal;
struct uci_package *p;
struct uci_element *e;
int uci_add_list(struct uci_context *ctx, struct uci_ptr *ptr)
{
/* NB: UCI_INTERNAL use means without delta tracking */
- bool internal = ctx->internal;
+ bool internal = ctx && ctx->internal;
struct uci_option *prev = NULL;
const char *value2 = NULL;
int uci_set(struct uci_context *ctx, struct uci_ptr *ptr)
{
/* NB: UCI_INTERNAL use means without delta tracking */
- bool internal = ctx->internal;
+ bool internal = ctx && ctx->internal;
UCI_HANDLE_ERR(ctx);
uci_expand_ptr(ctx, ptr, false);