return NULL;
}
+static union ucimap_data *
+ucimap_list_append(struct ucimap_list *list)
+{
+ if (unlikely(list->size <= list->n_items)) {
+ /* should not happen */
+ DPRINTF("ERROR: overflow while filling a list (size=%d)\n", list->size);
+ return NULL;
+ }
+ return &list->item[list->n_items++];
+}
+
+
static bool
ucimap_handle_fixup(struct uci_map *map, struct ucimap_fixup *f)
{
void *ptr = ucimap_find_section(map, f);
struct ucimap_list *list;
+ union ucimap_data *data;
if (!ptr)
return false;
break;
case UCIMAP_LIST:
list = f->data->list;
- list->item[list->n_items++].ptr = ptr;
+ data = ucimap_list_append(f->data->list);
+ if (!data)
+ return false;
+
+ data->ptr = ptr;
break;
}
return true;
int val;
if (ucimap_is_list(om->type) && !ucimap_is_fixup(om->type)) {
- if (unlikely(data->list->size <= data->list->n_items)) {
- /* should not happen */
- DPRINTF("ERROR: overflow while filling a list\n");
+ data = ucimap_list_append(data->list);
+ if (!data)
return;
- }
-
- data = &data->list->item[data->list->n_items++];
}
switch(om->type & UCIMAP_SUBTYPE) {
union ucimap_data *data;
struct uci_element *e;
int n_elements = 0;
+ int n_elements_alloc = 0;
int n_elements_custom = 0;
int size;
if (o->type == UCI_TYPE_LIST) {
uci_foreach_element(&o->v.list, tmp) {
- ucimap_count_alloc(om, &n_elements, &n_elements_custom);
+ ucimap_count_alloc(om, &n_elements_alloc, &n_elements_custom);
+ n_elements++;
}
} else if ((o->type == UCI_TYPE_STRING) &&
ucimap_is_list_auto(om->type)) {
break;
n_elements++;
- ucimap_count_alloc(om, &n_elements, &n_elements_custom);
+ ucimap_count_alloc(om, &n_elements_alloc, &n_elements_custom);
while (*data && !isspace(*data))
data++;
break;
}
/* add one more for the ucimap_list */
- n_alloc += n_elements + 1;
+ n_alloc += n_elements_alloc + 1;
n_alloc_custom += n_elements_custom;
size = sizeof(struct ucimap_list) +
n_elements * sizeof(union ucimap_data);