From: Alberto Leiva Popper Date: Tue, 12 Sep 2023 21:54:27 +0000 (-0600) Subject: Add ARRAYLIST_FOREACH_IDX X-Git-Tag: 1.6.0~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ea323adc097f8847710a20f19fb83828e2a6852;p=thirdparty%2FFORT-validator.git Add ARRAYLIST_FOREACH_IDX The old ARRAYLIST_FOREACH provided both a cursor and a counter. Most users weren't using the counter, so I separated them: The new ARRAYLIST_FOREACH uses a cursor, the new ARRAYLIST_FOREACH_IDX uses a counter. --- diff --git a/src/cert_stack.c b/src/cert_stack.c index 5ad5c1cd..c411c4f6 100644 --- a/src/cert_stack.c +++ b/src/cert_stack.c @@ -394,7 +394,6 @@ x509stack_store_serial(struct cert_stack *stack, BIGNUM *number) { struct metadata_node *meta; struct serial_number *cursor; - array_index i; struct serial_number duplicate; char *string; @@ -427,7 +426,7 @@ x509stack_store_serial(struct cert_stack *stack, BIGNUM *number) * * TODO I haven't seen this warning in a while. Review. */ - ARRAYLIST_FOREACH(&meta->serials, cursor, i) { + ARRAYLIST_FOREACH(&meta->serials, cursor) { if (BN_cmp(cursor->number, number) == 0) { BN2string(number, &string); pr_val_warn("Serial number '%s' is not unique. (Also found in '%s'.)", diff --git a/src/data_structure/array_list.h b/src/data_structure/array_list.h index 6a6ea5ac..686165c9 100644 --- a/src/data_structure/array_list.h +++ b/src/data_structure/array_list.h @@ -69,10 +69,16 @@ DEFINE_ARRAY_LIST_STRUCT(name, elem_type); \ DEFINE_ARRAY_LIST_FUNCTIONS(name, elem_type, static) -#define ARRAYLIST_FOREACH(list, node, index) for ( \ - (index) = 0, (node) = (list)->array; \ +#define ARRAYLIST_FOREACH(list, node) for ( \ + (node) = (list)->array; \ + (node) < (list)->array + (list)->len; \ + (node)++ \ +) + +#define ARRAYLIST_FOREACH_IDX(list, index) for ( \ + (index) = 0; \ (index) < (list)->len; \ - (index)++, (node)++ \ + (index)++ \ ) #endif /* SRC_DATA_STRUCTURE_ARRAY_LIST_H_ */ diff --git a/src/object/certificate.c b/src/object/certificate.c index 3c44c3b1..d1e12784 100644 --- a/src/object/certificate.c +++ b/src/object/certificate.c @@ -1932,12 +1932,11 @@ static int download_rpp(struct sia_uris *uris) { struct rpki_uri **node, *uri; - array_index index; if (uris->rpp.len == 0) return pr_val_err("SIA lacks both caRepository and rpkiNotify."); - ARRAYLIST_FOREACH(&uris->rpp, node, index) { + ARRAYLIST_FOREACH(&uris->rpp, node) { uri = *node; switch (uri_get_type(uri)) { case UT_RSYNC: diff --git a/src/rpp.c b/src/rpp.c index efa6333a..d9592cd7 100644 --- a/src/rpp.c +++ b/src/rpp.c @@ -241,7 +241,6 @@ void rpp_traverse(struct rpp *pp) { struct rpki_uri **uri; - array_index i; /* * A subtree should not invalidate the rest of the tree, so error codes @@ -258,13 +257,13 @@ rpp_traverse(struct rpp *pp) __cert_traverse(pp); /* Validate ROAs, apply validation_handler on them. */ - ARRAYLIST_FOREACH(&pp->roas, uri, i) + ARRAYLIST_FOREACH(&pp->roas, uri) roa_traverse(*uri, pp); /* * We don't do much with the ghostbusters right now. * Just validate them. */ - ARRAYLIST_FOREACH(&pp->ghostbusters, uri, i) + ARRAYLIST_FOREACH(&pp->ghostbusters, uri) ghostbusters_traverse(*uri, pp); } diff --git a/src/rrdp/rrdp_objects.c b/src/rrdp/rrdp_objects.c index b34f1a29..7d44259d 100644 --- a/src/rrdp/rrdp_objects.c +++ b/src/rrdp/rrdp_objects.c @@ -95,7 +95,6 @@ int deltas_head_sort(struct deltas_head *deltas, unsigned long max_serial) { unsigned long min_serial; - struct delta_head *cursor; array_index i; int error; @@ -105,7 +104,7 @@ deltas_head_sort(struct deltas_head *deltas, unsigned long max_serial) min_serial = max_serial + 1 - deltas->len; - ARRAYLIST_FOREACH(deltas, cursor, i) { + ARRAYLIST_FOREACH_IDX(deltas, i) { error = swap_until_sorted(deltas->array, i, min_serial, max_serial); if (error) diff --git a/src/rtr/db/delta.c b/src/rtr/db/delta.c index 84c73485..551cbd09 100644 --- a/src/rtr/db/delta.c +++ b/src/rtr/db/delta.c @@ -192,13 +192,12 @@ __foreach_v4(struct deltas_v4 *array, delta_vrp_foreach_cb cb, void *arg, { struct delta_vrp delta; struct delta_v4 *d; - array_index i; int error; delta.vrp.addr_fam = AF_INET; delta.flags = flags; - ARRAYLIST_FOREACH(array, d, i) { + ARRAYLIST_FOREACH(array, d) { delta.vrp.asn = d->as; delta.vrp.prefix.v4 = d->prefix.addr; delta.vrp.prefix_length = d->prefix.len; @@ -217,13 +216,12 @@ __foreach_v6(struct deltas_v6 *array, delta_vrp_foreach_cb cb, void *arg, { struct delta_vrp delta; struct delta_v6 *d; - array_index i; int error; delta.vrp.addr_fam = AF_INET6; delta.flags = flags; - ARRAYLIST_FOREACH(array, d, i) { + ARRAYLIST_FOREACH(array, d) { delta.vrp.asn = d->as; delta.vrp.prefix.v6 = d->prefix.addr; delta.vrp.prefix_length = d->prefix.len; @@ -242,12 +240,11 @@ __foreach_rk(struct deltas_rk *array, delta_router_key_foreach_cb cb, { struct delta_router_key delta; struct delta_rk *d; - array_index i; int error; delta.flags = flags; - ARRAYLIST_FOREACH(array, d, i) { + ARRAYLIST_FOREACH(array, d) { delta.router_key.as = d->as; memcpy(delta.router_key.ski, d->ski, RK_SKI_LEN); memcpy(delta.router_key.spk, d->spk, RK_SPKI_LEN); diff --git a/src/rtr/rtr.c b/src/rtr/rtr.c index d69c7f70..12d357a8 100644 --- a/src/rtr/rtr.c +++ b/src/rtr/rtr.c @@ -579,21 +579,17 @@ static enum poll_verdict fddb_poll(void) { struct pollfd *pollfds; /* array */ - - struct rtr_server *server; - struct rtr_client *client; struct pollfd *fd; - unsigned int nclients; unsigned int i; int error; pollfds = pcalloc(servers.len + clients.len, sizeof(struct pollfd)); - ARRAYLIST_FOREACH(&servers, server, i) - init_pollfd(&pollfds[i], server->fd); - ARRAYLIST_FOREACH(&clients, client, i) - init_pollfd(&pollfds[servers.len + i], client->fd); + ARRAYLIST_FOREACH_IDX(&servers, i) + init_pollfd(&pollfds[i], servers.array[i].fd); + ARRAYLIST_FOREACH_IDX(&clients, i) + init_pollfd(&pollfds[servers.len + i], clients.array[i].fd); error = poll(pollfds, servers.len + clients.len, 1000); @@ -750,12 +746,11 @@ int rtr_foreach_client(rtr_foreach_client_cb cb, void *arg) { struct rtr_client *client; - unsigned int i; int error = 0; mutex_lock(&lock); - ARRAYLIST_FOREACH(&clients, client, i) { + ARRAYLIST_FOREACH(&clients, client) { if (client->fd != -1) { error = cb(client, arg); if (error) diff --git a/src/slurm/db_slurm.c b/src/slurm/db_slurm.c index fb4869fc..3b033524 100644 --- a/src/slurm/db_slurm.c +++ b/src/slurm/db_slurm.c @@ -182,9 +182,8 @@ static bool prefix_filtered(struct db_slurm *db, struct slurm_prefix *prefix) { struct slurm_prefix_wrap *cursor; - array_index i; - ARRAYLIST_FOREACH(&db->lists.filter_pfx_al, cursor, i) + ARRAYLIST_FOREACH(&db->lists.filter_pfx_al, cursor) if (prefix_filtered_by(cursor, prefix)) return true; @@ -238,9 +237,8 @@ static bool bgpsec_filtered(struct db_slurm *db, struct slurm_bgpsec *bgpsec) { struct slurm_bgpsec_wrap *cursor; - array_index i; - ARRAYLIST_FOREACH(&db->lists.filter_bgps_al, cursor, i) + ARRAYLIST_FOREACH(&db->lists.filter_bgps_al, cursor) if (bgpsec_filtered_by(cursor, bgpsec)) return true; @@ -272,14 +270,13 @@ static bool prefix_exists(struct db_slurm *db, struct slurm_prefix *elem) { struct slurm_prefix_wrap *cursor; - array_index i; - ARRAYLIST_FOREACH(&db->lists.filter_pfx_al, cursor, i) + ARRAYLIST_FOREACH(&db->lists.filter_pfx_al, cursor) if (prefix_contained(&cursor->element, elem) || prefix_contained(elem, &cursor->element)) return true; - ARRAYLIST_FOREACH(&db->lists.assertion_pfx_al, cursor, i) + ARRAYLIST_FOREACH(&db->lists.assertion_pfx_al, cursor) if (prefix_contained(&cursor->element, elem) || prefix_contained(elem, &cursor->element)) return true; @@ -336,14 +333,13 @@ static bool bgpsec_exists(struct db_slurm *db, struct slurm_bgpsec *elem) { struct slurm_bgpsec_wrap *cursor; - array_index i; - ARRAYLIST_FOREACH(&db->lists.filter_bgps_al, cursor, i) + ARRAYLIST_FOREACH(&db->lists.filter_bgps_al, cursor) if (bgpsec_contained(&cursor->element, elem) || bgpsec_contained(elem, &cursor->element)) return true; - ARRAYLIST_FOREACH(&db->lists.assertion_bgps_al, cursor, i) + ARRAYLIST_FOREACH(&db->lists.assertion_bgps_al, cursor) if (bgpsec_contained(&cursor->element, elem) || bgpsec_contained(elem, &cursor->element)) return true; @@ -415,10 +411,9 @@ db_slurm_bgpsec_is_filtered(struct db_slurm *db, struct router_key const *key) object##_foreach_cb cb, void *arg) \ { \ struct slurm_##object##_wrap *cursor; \ - array_index i; \ int error; \ \ - ARRAYLIST_FOREACH(&lists->db_list, cursor, i) { \ + ARRAYLIST_FOREACH(&lists->db_list, cursor) { \ error = cb(&cursor->element, arg); \ if (error) \ return error; \ @@ -544,9 +539,8 @@ static void persist_filter_prefix(struct db_slurm *db) { struct slurm_prefix_wrap *cursor; - array_index i; - ARRAYLIST_FOREACH(&db->cache->filter_pfx_al, cursor, i) + ARRAYLIST_FOREACH(&db->cache->filter_pfx_al, cursor) al_filter_prefix_add(&db->lists.filter_pfx_al, cursor); } @@ -554,9 +548,8 @@ static void persist_filter_bgpsec(struct db_slurm *db) { struct slurm_bgpsec_wrap *cursor; - array_index i; - ARRAYLIST_FOREACH(&db->cache->filter_bgps_al, cursor, i) { + ARRAYLIST_FOREACH(&db->cache->filter_bgps_al, cursor) { al_filter_bgpsec_add(&db->lists.filter_bgps_al, cursor); slurm_bgpsec_wrap_refget(cursor); } @@ -566,9 +559,8 @@ static void persist_assertion_prefix(struct db_slurm *db) { struct slurm_prefix_wrap *cursor; - array_index i; - ARRAYLIST_FOREACH(&db->cache->assertion_pfx_al, cursor, i) + ARRAYLIST_FOREACH(&db->cache->assertion_pfx_al, cursor) al_assertion_prefix_add(&db->lists.assertion_pfx_al, cursor); } @@ -576,9 +568,8 @@ static void persist_assertion_bgpsec(struct db_slurm *db) { struct slurm_bgpsec_wrap *cursor; - array_index i; - ARRAYLIST_FOREACH(&db->cache->assertion_bgps_al, cursor, i) { + ARRAYLIST_FOREACH(&db->cache->assertion_bgps_al, cursor) { al_assertion_bgpsec_add(&db->lists.assertion_bgps_al, cursor); slurm_bgpsec_wrap_refget(cursor); }