From: pcarana Date: Thu, 21 Mar 2019 15:09:44 +0000 (-0600) Subject: Remove unnecessary indexing at some pointers X-Git-Tag: v0.0.2~52^2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c730bb578e504ab5c11f358e92ef2c18ce6ae18e;p=thirdparty%2FFORT-validator.git Remove unnecessary indexing at some pointers --- diff --git a/src/notify.c b/src/notify.c index bfebd3cb..25456feb 100644 --- a/src/notify.c +++ b/src/notify.c @@ -24,11 +24,10 @@ notify_clients(void) { struct client *clients, *ptr; size_t clients_len; - int i, error; + int error; clients_len = client_list(&clients); - ptr = clients; - for (i = 0; i < clients_len; i++, ptr++) { + for (ptr = clients; (ptr - clients) < clients_len; ptr++) { /* Send Serial Notify PDU */ error = send_notify(ptr->fd, ptr->rtr_version); /* Error? Log it */ diff --git a/src/rtr/pdu_sender.c b/src/rtr/pdu_sender.c index c60769bc..3cf291ea 100644 --- a/src/rtr/pdu_sender.c +++ b/src/rtr/pdu_sender.c @@ -202,8 +202,8 @@ send_ipv6_prefix_pdu(struct sender_common *common, struct vrp *vrp) int send_payload_pdus(struct sender_common *common) { - struct vrp *vrps; - unsigned int len, i; + struct vrp *vrps, *ptr; + unsigned int len; int error; vrps = malloc(sizeof(struct vrp)); @@ -211,15 +211,11 @@ send_payload_pdus(struct sender_common *common) if (len == 0) goto end; - for (i = 0; i < len; i++) { - /* - * TODO (review) Why are you indexing `vrps`? You did not - * allocate an array. - */ - if (vrps[i].in_addr_len == INET_ADDRSTRLEN) - error = send_ipv4_prefix_pdu(common, &vrps[i]); - else if (vrps[i].in_addr_len == INET6_ADDRSTRLEN) - error = send_ipv6_prefix_pdu(common, &vrps[i]); + for (ptr = vrps; (ptr - vrps) < len; ptr++) { + if (ptr->in_addr_len == INET_ADDRSTRLEN) + error = send_ipv4_prefix_pdu(common, ptr); + else if (ptr->in_addr_len == INET6_ADDRSTRLEN) + error = send_ipv6_prefix_pdu(common, ptr); else error = -EINVAL; diff --git a/src/vrps.c b/src/vrps.c index ebcbd4d9..8a0ad109 100644 --- a/src/vrps.c +++ b/src/vrps.c @@ -326,10 +326,10 @@ deltas_db_status(u_int32_t *serial) static void add_vrps_filtered(struct vrps *dst, struct vrps *src) { - int i; - for (i = 0; i < src->len; i++) - if (vrp_is_new(dst, &src->array[i])) - vrps_add(dst, &src->array[i]); + struct vrp *ptr; + for (ptr = src->array; (ptr - src->array) < src->len; ptr++) + if (vrp_is_new(dst, ptr)) + vrps_add(dst, ptr); } static void