]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
implicitly declare list elements in ISC_LIST_FOREACH macros
authorEvan Hunt <each@isc.org>
Thu, 20 Mar 2025 22:46:35 +0000 (15:46 -0700)
committerEvan Hunt <each@isc.org>
Mon, 31 Mar 2025 20:37:47 +0000 (13:37 -0700)
ISC_LIST_FOREACH and related macros now use 'typeof(list.head)' to
declare the list elements automatically; the caller no longer needs
to do so.

ISC_LIST_FOREACH_SAFE also now implicitly declares its own 'next'
pointer, so it only needs three parameters instead of four.

23 files changed:
bin/delv/delv.c
bin/dig/dig.c
bin/dig/dighost.c
bin/dig/nslookup.c
bin/nsupdate/nsupdate.c
bin/plugins/filter-a.c
bin/plugins/filter-aaaa.c
bin/tools/mdig.c
lib/dns/acl.c
lib/dns/client.c
lib/dns/include/dns/message.h
lib/dns/message.c
lib/dns/ncache.c
lib/dns/request.c
lib/dns/resolver.c
lib/dns/tkey.c
lib/dns/xfrin.c
lib/dns/zone.c
lib/isc/httpd.c
lib/isc/include/isc/list.h
lib/isc/log.c
lib/ns/query.c
lib/ns/xfrout.c

index f5c4ad997154608067bb63c4f6a4cd6052527219..bb57747a654523c6698aca80b4c230c8e9622a89 100644 (file)
@@ -1840,7 +1840,6 @@ static void
 resolve_cb(dns_client_t *client, const dns_name_t *query_name,
           dns_namelist_t *namelist, isc_result_t result) {
        char namestr[DNS_NAME_FORMATSIZE];
-       dns_rdataset_t *rdataset;
 
        if (result != ISC_R_SUCCESS && !yaml) {
                delv_log(ISC_LOG_ERROR, "resolution failed: %s",
@@ -1855,9 +1854,9 @@ resolve_cb(dns_client_t *client, const dns_name_t *query_name,
                printf("records:\n");
        }
 
-       dns_name_t *response_name;
        ISC_LIST_FOREACH (*namelist, response_name, link) {
-               for (rdataset = ISC_LIST_HEAD(response_name->list);
+               for (dns_rdataset_t *rdataset =
+                            ISC_LIST_HEAD(response_name->list);
                     rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link))
                {
                        printdata(rdataset, response_name);
@@ -1985,7 +1984,6 @@ recvresponse(void *arg) {
        }
 
        MSG_SECTION_FOREACH (response, DNS_SECTION_ANSWER, name) {
-               dns_rdataset_t *rdataset = NULL;
                dns_rdatatype_t prevtype = 0;
 
                ISC_LIST_FOREACH (name->list, rdataset, link) {
index 2862eb6b374b036bdcae22ef7c24836a096a031e..b8b6468c696e53455fb5f8522cc54fe7328be756 100644 (file)
@@ -579,7 +579,6 @@ dns64prefix_answer(dns_message_t *msg, isc_buffer_t *buf) {
 static isc_result_t
 short_answer(dns_message_t *msg, dns_messagetextflag_t flags, isc_buffer_t *buf,
             dig_query_t *query) {
-       dns_rdataset_t *rdataset;
        isc_result_t result, loopresult;
        dns_name_t empty_name;
        dns_rdata_t rdata = DNS_RDATA_INIT;
index 334ad2be8d7f1c337b634db35c0f08d62e094be0..5b4a6edda937900e2015375432295b98d4c7b475 100644 (file)
@@ -3696,7 +3696,6 @@ tcp_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) {
 static bool
 check_for_more_data(dig_lookup_t *lookup, dig_query_t *query,
                    dns_message_t *msg, isc_sockaddr_t *peer, int len) {
-       dns_rdataset_t *rdataset = NULL;
        dns_rdata_t rdata = DNS_RDATA_INIT;
        dns_rdata_soa_t soa;
        uint32_t ixfr_serial = lookup->ixfr_serial, serial;
@@ -4255,7 +4254,6 @@ recv_done(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region,
        } else {
                match = true;
                MSG_SECTION_FOREACH (msg, DNS_SECTION_QUESTION, name) {
-                       dns_rdataset_t *rdataset;
                        ISC_LIST_FOREACH (name->list, rdataset, link) {
                                if (l->rdtype != rdataset->type ||
                                    l->rdclass != rdataset->rdclass ||
index a6b30183f455e52d1fce6e806b66b334bd708808..f34145f0fa94fa5fcb5dd73b621664c519a96357 100644 (file)
@@ -198,7 +198,6 @@ printrdata(dns_rdata_t *rdata) {
 static isc_result_t
 printsection(dig_query_t *query, dns_message_t *msg, bool headers,
             dns_section_t section) {
-       dns_rdataset_t *rdataset = NULL;
        dns_rdata_t rdata = DNS_RDATA_INIT;
        char namebuf[DNS_NAME_FORMATSIZE];
 
@@ -248,7 +247,6 @@ printsection(dig_query_t *query, dns_message_t *msg, bool headers,
 static isc_result_t
 detailsection(dig_query_t *query, dns_message_t *msg, bool headers,
              dns_section_t section) {
-       dns_rdataset_t *rdataset = NULL;
        dns_rdata_t rdata = DNS_RDATA_INIT;
        char namebuf[DNS_NAME_FORMATSIZE];
 
index 30bf9a15c36989dd1bf2433a4211b58f61192b0c..43f1ed1bfb98cdcd84fffe04938def20eb71d4a4 100644 (file)
@@ -2181,17 +2181,16 @@ evaluate_checksvcb(char *cmdline) {
 
 static void
 setzone(dns_name_t *zonename) {
+       dns_namelist_t *secs = updatemsg->sections;
        dns_name_t *name = NULL;
-       dns_rdataset_t *rdataset = NULL, *next_rds = NULL;
 
-       dns_namelist_t *secs = updatemsg->sections;
        if (!ISC_LIST_EMPTY(secs[DNS_SECTION_ZONE])) {
                INSIST(updatemsg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
 
                name = ISC_LIST_HEAD(secs[DNS_SECTION_ZONE]);
                ISC_LIST_UNLINK(secs[DNS_SECTION_ZONE], name, link);
 
-               ISC_LIST_FOREACH_SAFE (name->list, rdataset, link, next_rds) {
+               ISC_LIST_FOREACH_SAFE (name->list, rdataset, link) {
                        ISC_LIST_UNLINK(name->list, rdataset, link);
                        dns_rdataset_disassociate(rdataset);
                        dns_message_puttemprdataset(updatemsg, &rdataset);
@@ -2200,6 +2199,8 @@ setzone(dns_name_t *zonename) {
        }
 
        if (zonename != NULL) {
+               dns_rdataset_t *rdataset = NULL;
+
                dns_message_gettempname(updatemsg, &name);
                dns_name_clone(zonename, name);
                dns_message_gettemprdataset(updatemsg, &rdataset);
@@ -2824,20 +2825,21 @@ lookforsoa:
                goto lookforsoa;
        }
 
-       ISC_LIST_FOREACH (rcvmsg->sections[section], name, link) {
+       ISC_LIST_FOREACH (rcvmsg->sections[section], n, link) {
                soaset = NULL;
-               result = dns_message_findtype(name, dns_rdatatype_soa, 0,
-                                             &soaset);
+               result = dns_message_findtype(n, dns_rdatatype_soa, 0, &soaset);
                if (result == ISC_R_SUCCESS) {
+                       name = n;
                        break;
                }
                if (section == DNS_SECTION_ANSWER) {
                        dns_rdataset_t *tset = NULL;
-                       if (dns_message_findtype(name, dns_rdatatype_cname, 0,
+                       if (dns_message_findtype(n, dns_rdatatype_cname, 0,
                                                 &tset) == ISC_R_SUCCESS ||
-                           dns_message_findtype(name, dns_rdatatype_dname, 0,
+                           dns_message_findtype(n, dns_rdatatype_dname, 0,
                                                 &tset) == ISC_R_SUCCESS)
                        {
+                               name = n;
                                seencname = true;
                                break;
                        }
index c990206fc4976adfe9aaa594eb62f8b6785d200c..30d0125530558d7f073bc2dbcb27bfc08f422bcd 100644 (file)
@@ -540,14 +540,14 @@ process_name(query_ctx_t *qctx, filter_a_t mode, const dns_name_t *name,
        dns_rdataset_t *rdataset = NULL, *sigrdataset = NULL;
        isc_result_t result;
        bool modified = false;
+       dns_name_t *n = UNCONST(name);
 
        if (only_if_aaaa_exists) {
-               CHECK(dns_message_findtype(name, dns_rdatatype_aaaa, 0, NULL));
+               CHECK(dns_message_findtype(n, dns_rdatatype_aaaa, 0, NULL));
        }
 
-       (void)dns_message_findtype(name, type, 0, &rdataset);
-       (void)dns_message_findtype(name, dns_rdatatype_rrsig, type,
-                                  &sigrdataset);
+       (void)dns_message_findtype(n, type, 0, &rdataset);
+       (void)dns_message_findtype(n, dns_rdatatype_rrsig, type, &sigrdataset);
 
        if (rdataset != NULL &&
            (sigrdataset == NULL || !WANTDNSSEC(qctx->client) ||
index dcd5554d1625df6e21ac467e88102fb66ad067bb..8202a8b0cd3beb60ebdad9fc11720b7509c0e656 100644 (file)
@@ -544,14 +544,14 @@ process_name(query_ctx_t *qctx, filter_aaaa_t mode, const dns_name_t *name,
        dns_rdataset_t *rdataset = NULL, *sigrdataset = NULL;
        isc_result_t result;
        bool modified = false;
+       dns_name_t *n = UNCONST(name);
 
        if (only_if_a_exists) {
-               CHECK(dns_message_findtype(name, dns_rdatatype_a, 0, NULL));
+               CHECK(dns_message_findtype(n, dns_rdatatype_a, 0, NULL));
        }
 
-       (void)dns_message_findtype(name, type, 0, &rdataset);
-       (void)dns_message_findtype(name, dns_rdatatype_rrsig, type,
-                                  &sigrdataset);
+       (void)dns_message_findtype(n, type, 0, &rdataset);
+       (void)dns_message_findtype(n, dns_rdatatype_rrsig, type, &sigrdataset);
 
        if (rdataset != NULL &&
            (sigrdataset == NULL || !WANTDNSSEC(qctx->client) ||
index a4fa4e1274bfdb3f459e746b1ba6ca100b6236a5..f4024c75a9b88f3d2a54422455b6275445f5e07f 100644 (file)
@@ -427,7 +427,6 @@ repopulate_buffer:
                }
                CHECK("dns_message_sectiontotext", result);
        } else if (display_answer) {
-               dns_rdataset_t *rdataset;
                isc_result_t loopresult;
                dns_name_t empty_name;
                dns_rdata_t rdata = DNS_RDATA_INIT;
index d4e7ee819039f5d6dd79fc2ea163289c22385d5c..07c4881ef53f5964049aeb9626ef862ddc0c4dab 100644 (file)
@@ -462,11 +462,7 @@ dns_aclelement_match(const isc_netaddr_t *reqaddr, const dns_name_t *reqsigner,
 
 static void
 dns__acl_destroy_port_transports(dns_acl_t *acl) {
-       dns_acl_port_transports_t *port_proto = NULL;
-       dns_acl_port_transports_t *next = NULL;
-       ISC_LIST_FOREACH_SAFE (acl->ports_and_transports, port_proto, link,
-                              next)
-       {
+       ISC_LIST_FOREACH_SAFE (acl->ports_and_transports, port_proto, link) {
                ISC_LIST_DEQUEUE(acl->ports_and_transports, port_proto, link);
                isc_mem_put(acl->mctx, port_proto, sizeof(*port_proto));
        }
index 1949bd34abc44d7dc69f71e609595b641ac4fcc4..113c3b2641d783c127ae1c7f2f961b95b48ae860 100644 (file)
@@ -824,10 +824,9 @@ client_resfind(resctx_t *rctx, dns_fetchresponse_t *resp) {
        } while (want_restart);
 
        if (send_event) {
-               dns_name_t *next_name;
-               ISC_LIST_FOREACH_SAFE (rctx->namelist, name, link, next_name) {
-                       ISC_LIST_UNLINK(rctx->namelist, name, link);
-                       ISC_LIST_APPEND(rctx->rev->answerlist, name, link);
+               ISC_LIST_FOREACH_SAFE (rctx->namelist, n, link) {
+                       ISC_LIST_UNLINK(rctx->namelist, n, link);
+                       ISC_LIST_APPEND(rctx->rev->answerlist, n, link);
                }
 
                rctx->rev->result = result;
@@ -840,14 +839,12 @@ static void
 resolve_done(void *arg) {
        dns_clientresume_t *rev = (dns_clientresume_t *)arg;
        resarg_t *resarg = rev->arg;
-       dns_name_t *name = NULL;
        isc_result_t result;
 
        resarg->result = rev->result;
        resarg->vresult = rev->vresult;
 
-       dns_name_t *new_name;
-       ISC_LIST_FOREACH_SAFE (rev->answerlist, name, link, new_name) {
+       ISC_LIST_FOREACH_SAFE (rev->answerlist, name, link) {
                ISC_LIST_UNLINK(rev->answerlist, name, link);
                ISC_LIST_APPEND(*resarg->namelist, name, link);
        }
@@ -1003,20 +1000,17 @@ dns_client_resolve(dns_client_t *client, const dns_name_t *name,
 
 void
 dns_client_freeresanswer(dns_client_t *client, dns_namelist_t *namelist) {
-       dns_name_t *name, *new_name;
-       dns_rdataset_t *rdataset, *new_rdataset;
-
        REQUIRE(DNS_CLIENT_VALID(client));
        REQUIRE(namelist != NULL);
 
-       ISC_LIST_FOREACH_SAFE (*namelist, name, link, new_name) {
+       ISC_LIST_FOREACH_SAFE (*namelist, name, link) {
                ISC_LIST_UNLINK(*namelist, name, link);
 
-               ISC_LIST_FOREACH_SAFE (name->list, rdataset, link, new_rdataset)
-               {
+               ISC_LIST_FOREACH_SAFE (name->list, rdataset, link) {
                        ISC_LIST_UNLINK(name->list, rdataset, link);
                        putrdataset(client->mctx, &rdataset);
                }
+
                dns_name_free(name, client->mctx);
                isc_mem_put(client->mctx, name, sizeof(*name));
        }
index 69e2b7b6f353e7a1824bd101cb8583b692d0c902..81458aa68c4116b69a4fb689dcc1c5ee2e2d60c6 100644 (file)
@@ -804,7 +804,7 @@ dns_message_findname(dns_message_t *msg, dns_section_t section,
  */
 
 isc_result_t
-dns_message_findtype(const dns_name_t *name, dns_rdatatype_t type,
+dns_message_findtype(dns_name_t *name, dns_rdatatype_t type,
                     dns_rdatatype_t covers, dns_rdataset_t **rdataset);
 /*%<
  * Search the name for the specified type.  If it is found, *rdataset is
index 989b0a3832e25f1622332e8dc3b0f06ff20cb84d..099ceb119ea4c14c148269b8cc1e6ffdcfd9d6e6 100644 (file)
@@ -442,11 +442,8 @@ msginit(dns_message_t *m) {
 
 static void
 msgresetname(dns_message_t *msg, dns_name_t *name) {
-       dns_rdataset_t *rds = NULL, *next_rds = NULL;
-
-       ISC_LIST_FOREACH_SAFE (name->list, rds, link, next_rds) {
+       ISC_LIST_FOREACH_SAFE (name->list, rds, link) {
                ISC_LIST_UNLINK(name->list, rds, link);
-
                dns__message_putassociatedrdataset(msg, &rds);
        }
 }
@@ -455,14 +452,9 @@ static void
 msgresetnames(dns_message_t *msg, unsigned int first_section) {
        /* Clean up name lists. */
        for (size_t i = first_section; i < DNS_SECTION_MAX; i++) {
-               dns_name_t *name = NULL, *next_name = NULL;
-
-               ISC_LIST_FOREACH_SAFE (msg->sections[i], name, link, next_name)
-               {
+               ISC_LIST_FOREACH_SAFE (msg->sections[i], name, link) {
                        ISC_LIST_UNLINK(msg->sections[i], name, link);
-
                        msgresetname(msg, name);
-
                        dns_message_puttempname(msg, &name);
                }
        }
@@ -765,8 +757,6 @@ name_match(void *node, const void *key) {
 static isc_result_t
 findname(dns_name_t **foundname, const dns_name_t *target,
         dns_namelist_t *section) {
-       dns_name_t *name = NULL;
-
        ISC_LIST_FOREACH_REV (*section, name, link) {
                if (dns_name_equal(name, target)) {
                        if (foundname != NULL) {
@@ -801,17 +791,14 @@ rds_match(void *node, const void *key0) {
 }
 
 isc_result_t
-dns_message_findtype(const dns_name_t *name, dns_rdatatype_t type,
+dns_message_findtype(dns_name_t *name, dns_rdatatype_t type,
                     dns_rdatatype_t covers, dns_rdataset_t **rdatasetp) {
-       dns_rdataset_t *rds = NULL;
-
        REQUIRE(name != NULL);
        REQUIRE(rdatasetp == NULL || *rdatasetp == NULL);
 
        ISC_LIST_FOREACH_REV (name->list, rds, link) {
                if (rds->type == type && rds->covers == covers) {
                        SET_IF_NOT_NULL(rdatasetp, rds);
-
                        return ISC_R_SUCCESS;
                }
        }
@@ -923,7 +910,6 @@ getrdata(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t dctx,
 
 static void
 cleanup_name_hashmaps(dns_namelist_t *section) {
-       dns_name_t *name = NULL;
        ISC_LIST_FOREACH (*section, name, link) {
                if (name->hashmap != NULL) {
                        isc_hashmap_destroy(&name->hashmap);
@@ -1883,9 +1869,9 @@ update_min_section_ttl(dns_message_t *restrict msg,
 isc_result_t
 dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid,
                          unsigned int options) {
-       dns_namelist_t *section;
-       dns_name_t *name, *next_name;
-       dns_rdataset_t *rdataset, *next_rdataset;
+       dns_namelist_t *section = NULL;
+       dns_name_t *name = NULL;
+       dns_rdataset_t *rdataset = NULL;
        unsigned int count, total;
        isc_result_t result;
        isc_buffer_t st; /* for rollbacks */
@@ -1989,24 +1975,20 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid,
                        return ISC_R_SUCCESS;
                }
 
-               ISC_LIST_FOREACH_SAFE (*section, name, link, next_name) {
-                       rdataset = ISC_LIST_HEAD(name->list);
-                       while (rdataset != NULL) {
-                               next_rdataset = ISC_LIST_NEXT(rdataset, link);
-
-                               if ((rdataset->attributes &
+               ISC_LIST_FOREACH_SAFE (*section, n, link) {
+                       ISC_LIST_FOREACH_SAFE (n->list, rds, link) {
+                               if ((rds->attributes &
                                     DNS_RDATASETATTR_RENDERED) != 0)
                                {
-                                       goto next;
+                                       continue;
                                }
 
                                if (((options & DNS_MESSAGERENDER_ORDERED) ==
                                     0) &&
                                    (sectionid == DNS_SECTION_ADDITIONAL) &&
-                                   wrong_priority(rdataset, pass,
-                                                  preferred_glue))
+                                   wrong_priority(rds, pass, preferred_glue))
                                {
-                                       goto next;
+                                       continue;
                                }
 
                                st = *(msg->buffer);
@@ -2014,14 +1996,12 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid,
                                count = 0;
                                if (partial) {
                                        result = dns_rdataset_towirepartial(
-                                               rdataset, name, msg->cctx,
-                                               msg->buffer, rd_options, &count,
-                                               NULL);
+                                               rds, n, msg->cctx, msg->buffer,
+                                               rd_options, &count, NULL);
                                } else {
                                        result = dns_rdataset_towire(
-                                               rdataset, name, msg->cctx,
-                                               msg->buffer, rd_options,
-                                               &count);
+                                               rds, n, msg->cctx, msg->buffer,
+                                               rd_options, &count);
                                }
 
                                total += count;
@@ -2059,24 +2039,19 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid,
                                 * If we have rendered non-validated data,
                                 * ensure that the AD bit is not set.
                                 */
-                               if (rdataset->trust != dns_trust_secure &&
+                               if (rds->trust != dns_trust_secure &&
                                    (sectionid == DNS_SECTION_ANSWER ||
                                     sectionid == DNS_SECTION_AUTHORITY))
                                {
                                        msg->flags &= ~DNS_MESSAGEFLAG_AD;
                                }
-                               if (OPTOUT(rdataset)) {
+                               if (OPTOUT(rds)) {
                                        msg->flags &= ~DNS_MESSAGEFLAG_AD;
                                }
 
-                               update_min_section_ttl(msg, sectionid,
-                                                      rdataset);
-
-                               rdataset->attributes |=
-                                       DNS_RDATASETATTR_RENDERED;
+                               update_min_section_ttl(msg, sectionid, rds);
 
-                       next:
-                               rdataset = next_rdataset;
+                               rds->attributes |= DNS_RDATASETATTR_RENDERED;
                        }
                }
        } while (--pass != 0);
@@ -2305,7 +2280,6 @@ dns_message_renderreset(dns_message_t *msg) {
                msg->cursors[i] = NULL;
                msg->counts[i] = 0;
                MSG_SECTION_FOREACH (msg, i, name) {
-                       dns_rdataset_t *rds = NULL;
                        ISC_LIST_FOREACH (name->list, rds, link) {
                                rds->attributes &= ~DNS_RDATASETATTR_RENDERED;
                        }
@@ -3306,7 +3280,6 @@ dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
        msg->indent.count += has_yaml;
 
        MSG_SECTION_FOREACH (msg, section, name) {
-               dns_rdataset_t *rds = NULL;
                ISC_LIST_FOREACH (name->list, rds, link) {
                        if (section == DNS_SECTION_ANSWER &&
                            rds->type == dns_rdatatype_soa)
@@ -4997,7 +4970,6 @@ message_authority_soa_min(dns_message_t *msg, dns_ttl_t *ttlp) {
        }
 
        MSG_SECTION_FOREACH (msg, DNS_SECTION_AUTHORITY, name) {
-               dns_rdataset_t *rds = NULL;
                ISC_LIST_FOREACH (name->list, rds, link) {
                        if ((rds->attributes & DNS_RDATASETATTR_RENDERED) == 0)
                        {
index 6c7ee711720ced7616c853a285ef4916ff06d003..9b319d7d0590112a32dbdf11700e408eeb25b06c 100644 (file)
@@ -128,7 +128,6 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node,
          dns_rdataset_t *addedrdataset) {
        isc_buffer_t buffer;
        isc_region_t r;
-       dns_rdataset_t *rdataset;
        dns_rdatatype_t type;
        dns_ttl_t ttl;
        dns_trust_t trust;
index 3b30599a491f730b9d69d2a486b9fdcb22c2b366..3d8521c0fc713de80a6e02f3cab9b2243da64d36 100644 (file)
@@ -172,10 +172,9 @@ dns_requestmgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr,
 static void
 requests_shutdown(void *arg) {
        dns_requestmgr_t *requestmgr = arg;
-       dns_request_t *request = NULL, *next = NULL;
        uint32_t tid = isc_tid();
 
-       ISC_LIST_FOREACH_SAFE (requestmgr->requests[tid], request, link, next) {
+       ISC_LIST_FOREACH_SAFE (requestmgr->requests[tid], request, link) {
                req_log(ISC_LOG_DEBUG(3), "%s(%" PRIu32 ": request %p",
                        __func__, tid, request);
                if (DNS_REQUEST_COMPLETE(request)) {
index 11e7b500788110eb6eba075c5fa22eac8a48f01e..eb8c7e6c8a325554ca25edde5e77abfe360ea23e 100644 (file)
@@ -4984,8 +4984,6 @@ cleanup_nameservers:
  */
 static bool
 is_lame(fetchctx_t *fctx, dns_message_t *message) {
-       dns_rdataset_t *rdataset;
-
        if (message->rcode != dns_rcode_noerror &&
            message->rcode != dns_rcode_yxdomain &&
            message->rcode != dns_rcode_nxdomain)
@@ -5314,8 +5312,6 @@ validated(void *arg) {
        dns_fetchresponse_t *hresp = NULL;
        dns_rdataset_t *ardataset = NULL;
        dns_rdataset_t *asigrdataset = NULL;
-       dns_rdataset_t *rdataset = NULL;
-       dns_rdataset_t *sigrdataset = NULL;
        dns_resolver_t *res = NULL;
        dns_valarg_t *valarg = NULL;
        fetchctx_t *fctx = NULL;
@@ -5649,6 +5645,8 @@ answer_response:
         */
        MSG_SECTION_FOREACH (message, DNS_SECTION_AUTHORITY, name) {
                ISC_LIST_FOREACH (name->list, rdataset, link) {
+                       dns_rdataset_t *sigrdataset = NULL;
+
                        if ((rdataset->type != dns_rdatatype_ns &&
                             rdataset->type != dns_rdatatype_soa &&
                             rdataset->type != dns_rdatatype_nsec) ||
@@ -5657,13 +5655,13 @@ answer_response:
                                continue;
                        }
 
-                       ISC_LIST_FOREACH (name->list, sigrdataset, link) {
-                               if (sigrdataset->type != dns_rdatatype_rrsig ||
-                                   sigrdataset->covers != rdataset->type)
+                       ISC_LIST_FOREACH (name->list, s, link) {
+                               if (s->type == dns_rdatatype_rrsig &&
+                                   s->covers == rdataset->type)
                                {
-                                       continue;
+                                       sigrdataset = s;
+                                       break;
                                }
-                               break;
                        }
                        if (sigrdataset == NULL ||
                            sigrdataset->trust != dns_trust_secure)
@@ -5838,7 +5836,7 @@ fctx_log(void *arg, int level, const char *fmt, ...) {
 static isc_result_t
 findnoqname(fetchctx_t *fctx, dns_message_t *message, dns_name_t *name,
            dns_rdatatype_t type, dns_name_t **noqnamep) {
-       dns_rdataset_t *nrdataset, *sigrdataset;
+       dns_rdataset_t *sigrdataset = NULL;
        dns_rdata_rrsig_t rrsig;
        isc_result_t result;
        unsigned int labels;
@@ -5858,12 +5856,9 @@ findnoqname(fetchctx_t *fctx, dns_message_t *message, dns_name_t *name,
        /*
         * Find the SIG for this rdataset, if we have it.
         */
-       for (sigrdataset = ISC_LIST_HEAD(name->list); sigrdataset != NULL;
-            sigrdataset = ISC_LIST_NEXT(sigrdataset, link))
-       {
-               if (sigrdataset->type == dns_rdatatype_rrsig &&
-                   sigrdataset->covers == type)
-               {
+       ISC_LIST_FOREACH (name->list, sig, link) {
+               if (sig->type == dns_rdatatype_rrsig && sig->covers == type) {
+                       sigrdataset = sig;
                        break;
                }
        }
@@ -6614,7 +6609,6 @@ ncache_message(fetchctx_t *fctx, dns_message_t *message,
                 * Mark all rdatasets as pending.
                 */
                MSG_SECTION_FOREACH (message, DNS_SECTION_AUTHORITY, tname) {
-                       dns_rdataset_t *trdataset = NULL;
                        ISC_LIST_FOREACH (tname->list, trdataset, link) {
                                trdataset->trust = dns_trust_pending_answer;
                        }
@@ -7296,16 +7290,13 @@ cleanup:
 
 static void
 checknamessection(dns_message_t *message, dns_section_t section) {
-       isc_result_t result;
-       dns_rdata_t rdata = DNS_RDATA_INIT;
-       dns_rdataset_t *rdataset;
-
        MSG_SECTION_FOREACH (message, section, name) {
                ISC_LIST_FOREACH (name->list, rdataset, link) {
-                       for (result = dns_rdataset_first(rdataset);
+                       for (isc_result_t result = dns_rdataset_first(rdataset);
                             result == ISC_R_SUCCESS;
                             result = dns_rdataset_next(rdataset))
                        {
+                               dns_rdata_t rdata = DNS_RDATA_INIT;
                                dns_rdataset_current(rdataset, &rdata);
                                if (!dns_rdata_checkowner(name, rdata.rdclass,
                                                          rdata.type, false) ||
@@ -7314,7 +7305,6 @@ checknamessection(dns_message_t *message, dns_section_t section) {
                                        rdataset->attributes |=
                                                DNS_RDATASETATTR_CHECKNAMES;
                                }
-                               dns_rdata_reset(&rdata);
                        }
                }
        }
@@ -7486,9 +7476,8 @@ log_zoneversion(unsigned char *version, size_t version_len, unsigned char *nsid,
 
 static bool
 betterreferral(respctx_t *rctx) {
-       dns_rdataset_t *rdataset;
-
        dns_message_t *msg = rctx->query->rmessage;
+
        MSG_SECTION_FOREACH (msg, DNS_SECTION_AUTHORITY, name) {
                if (!isstrictsubdomain(name, rctx->fctx->domain)) {
                        continue;
@@ -8572,9 +8561,8 @@ rctx_answer_positive(respctx_t *rctx) {
 static void
 rctx_answer_scan(respctx_t *rctx) {
        fetchctx_t *fctx = rctx->fctx;
-       dns_rdataset_t *rdataset = NULL;
-
        dns_message_t *msg = rctx->query->rmessage;
+
        MSG_SECTION_FOREACH (msg, DNS_SECTION_ANSWER, name) {
                int order;
                unsigned int nlabels;
@@ -8913,8 +8901,6 @@ rctx_authority_positive(respctx_t *rctx) {
        dns_message_t *msg = rctx->query->rmessage;
        MSG_SECTION_FOREACH (msg, DNS_SECTION_AUTHORITY, name) {
                if (!name_external(name, dns_rdatatype_ns, fctx)) {
-                       dns_rdataset_t *rdataset = NULL;
-
                        /*
                         * We expect to find NS or SIG NS rdatasets, and
                         * nothing else.
@@ -9106,7 +9092,6 @@ static isc_result_t
 rctx_authority_negative(respctx_t *rctx) {
        fetchctx_t *fctx = rctx->fctx;
        dns_section_t section;
-       dns_rdataset_t *rdataset = NULL;
 
        section = DNS_SECTION_AUTHORITY;
 
@@ -9250,7 +9235,6 @@ static isc_result_t
 rctx_authority_dnssec(respctx_t *rctx) {
        isc_result_t result;
        fetchctx_t *fctx = rctx->fctx;
-       dns_rdataset_t *rdataset = NULL;
 
        dns_message_t *msg = rctx->query->rmessage;
        MSG_SECTION_FOREACH (msg, DNS_SECTION_AUTHORITY, name) {
@@ -9509,7 +9493,6 @@ again:
 
        dns_message_t *msg = rctx->query->rmessage;
        MSG_SECTION_FOREACH (msg, section, name) {
-               dns_rdataset_t *rdataset;
                if (!name->attributes.chase) {
                        continue;
                }
index b6a241a6bdeb7b13a2bdb2d40af0f6a8ef98c234..bf137aa69c22f51e2ef748ffbfe8dab84d3870c3 100644 (file)
@@ -154,13 +154,9 @@ add_rdata_to_list(dns_message_t *msg, dns_name_t *name, dns_rdata_t *rdata,
 
 static void
 free_namelist(dns_message_t *msg, dns_namelist_t *namelist) {
-       dns_name_t *name = NULL, *new_name = NULL;
-
-       ISC_LIST_FOREACH_SAFE (*namelist, name, link, new_name) {
-               dns_rdataset_t *set = NULL, *new_set = NULL;
+       ISC_LIST_FOREACH_SAFE (*namelist, name, link) {
                ISC_LIST_UNLINK(*namelist, name, link);
-
-               ISC_LIST_FOREACH_SAFE (name->list, set, link, new_set) {
+               ISC_LIST_FOREACH_SAFE (name->list, set, link) {
                        ISC_LIST_UNLINK(name->list, set, link);
                        if (dns_rdataset_isassociated(set)) {
                                dns_rdataset_disassociate(set);
@@ -354,7 +350,7 @@ dns_tkey_processquery(dns_message_t *msg, dns_tkeyctx_t *tctx,
                      dns_tsigkeyring_t *ring) {
        isc_result_t result = ISC_R_SUCCESS;
        dns_rdata_tkey_t tkeyin, tkeyout;
-       dns_name_t *qname = NULL, *name = NULL;
+       dns_name_t *qname = NULL;
        dns_name_t *keyname = NULL, *signer = NULL;
        dns_name_t tsigner = DNS_NAME_INITEMPTY;
        dns_fixedname_t fkeyname;
@@ -378,11 +374,10 @@ dns_tkey_processquery(dns_message_t *msg, dns_tkeyctx_t *tctx,
 
        qname = ISC_LIST_HEAD(msg->sections[DNS_SECTION_QUESTION]);
 
-       /*
-        * Look for a TKEY record that matches the question.
+       /* * Look for a TKEY record that matches the question.
         */
        result = dns_message_findname(msg, DNS_SECTION_ADDITIONAL, qname,
-                                     dns_rdatatype_tkey, 0, &name, &tkeyset);
+                                     dns_rdatatype_tkey, 0, NULL, &tkeyset);
        if (result != ISC_R_SUCCESS) {
                result = DNS_R_FORMERR;
                tkey_log("dns_tkey_processquery: couldn't find a TKEY "
@@ -509,8 +504,7 @@ dns_tkey_processquery(dns_message_t *msg, dns_tkeyctx_t *tctx,
        RETERR(dns_message_reply(msg, true));
        add_rdata_to_list(msg, keyname, &rdata, 0, &namelist);
 
-       dns_name_t *new_name;
-       ISC_LIST_FOREACH_SAFE (namelist, name, link, new_name) {
+       ISC_LIST_FOREACH_SAFE (namelist, name, link) {
                ISC_LIST_UNLINK(namelist, name, link);
                dns_message_addname(msg, name, DNS_SECTION_ANSWER);
        }
index 570abef2110754e12ba80f50bdbc72b1d0edfb20..6751c9c99f51df25e9ba913d8daebcf6115c3460 100644 (file)
@@ -1973,8 +1973,6 @@ xfrin_recv_done(isc_result_t result, isc_region_t *region, void *arg) {
        }
 
        MSG_SECTION_FOREACH (msg, DNS_SECTION_ANSWER, name) {
-               dns_rdataset_t *rds = NULL;
-
                LIBDNS_XFRIN_RECV_ANSWER(xfr, xfr->info, msg);
 
                ISC_LIST_FOREACH (name->list, rds, link) {
index 3ae40953ceef59fdd5892a9519be5dac33cc4985..639e595cc7788124d26955eaa40db8cd44b52a85 100644 (file)
@@ -13597,7 +13597,7 @@ save_nsrrset(dns_message_t *message, dns_name_t *name,
        isc_result_t result;
        dns_rdata_t rdata = DNS_RDATA_INIT;
        bool has_glue = false;
-       dns_name_t *ns_name;
+
        /*
         * List of NS entries in answer, keep names that will be used
         * to resolve missing A/AAAA glue for each entry.
@@ -13725,9 +13725,8 @@ save_nsrrset(dns_message_t *message, dns_name_t *name,
 
        result = ISC_R_SUCCESS;
 
-       dns_name_t *new_ns_name;
 done:
-       ISC_LIST_FOREACH_SAFE (ns_list, ns_name, link, new_ns_name) {
+       ISC_LIST_FOREACH_SAFE (ns_list, ns_name, link) {
                ISC_LIST_UNLINK(ns_list, ns_name, link);
                dns_name_free(ns_name, cb_args->stub->mctx);
                isc_mem_put(cb_args->stub->mctx, ns_name, sizeof(*ns_name));
@@ -16189,7 +16188,6 @@ dnssec_log(dns_zone_t *zone, int level, const char *fmt, ...) {
 
 static int
 message_count(dns_message_t *msg, dns_section_t section, dns_rdatatype_t type) {
-       dns_rdataset_t *curr;
        int count = 0;
 
        MSG_SECTION_FOREACH (msg, section, name) {
@@ -21134,7 +21132,6 @@ checkds_done(void *arg) {
        /* Lookup DS RRset. */
 
        MSG_SECTION_FOREACH (message, DNS_SECTION_ANSWER, name) {
-               dns_rdataset_t *rdataset;
                if (dns_name_compare(&zone->origin, name) != 0) {
                        continue;
                }
index 320d72e6503b9db7733039ed190ff5951ab5acd3..c2b74a0ead352e259ec40e9d97fc7aa9737021a5 100644 (file)
@@ -290,8 +290,7 @@ destroy_httpdmgr(isc_httpdmgr_t *httpdmgr) {
         * Clear out the list of all actions we know about.  Just free the
         * memory.
         */
-       isc_httpdurl_t *url, *next;
-       ISC_LIST_FOREACH_SAFE (httpdmgr->urls, url, link, next) {
+       ISC_LIST_FOREACH_SAFE (httpdmgr->urls, url, link) {
                isc_mem_free(httpdmgr->mctx, url->url);
                ISC_LIST_UNLINK(httpdmgr->urls, url, link);
                isc_mem_put(httpdmgr->mctx, url, sizeof(isc_httpdurl_t));
@@ -780,8 +779,9 @@ prepare_response(void *arg) {
        }
 
        LOCK(&mgr->lock);
-       ISC_LIST_FOREACH (mgr->urls, url, link) {
-               if (strncmp(path, url->url, path_len) == 0) {
+       ISC_LIST_FOREACH (mgr->urls, u, link) {
+               if (strncmp(path, u->url, path_len) == 0) {
+                       url = u;
                        break;
                }
        }
@@ -978,8 +978,7 @@ isc_httpdmgr_shutdown(isc_httpdmgr_t **httpdmgrp) {
 
        LOCK(&httpdmgr->lock);
 
-       isc_httpd_t *httpd = NULL, *next = NULL;
-       ISC_LIST_FOREACH_SAFE (httpdmgr->running, httpd, link, next) {
+       ISC_LIST_FOREACH_SAFE (httpdmgr->running, httpd, link) {
                if (httpd->handle != NULL) {
                        httpd_request(httpd->handle, ISC_R_SUCCESS, NULL,
                                      httpd);
index 9668e89f9898cb10f5ed7b27ffe6ee91d07bc503..fd18a01d64878861c63de1a7a5fa01f5799d99bf 100644 (file)
        }
 
 /* clang-format off */
-#define ISC_LIST_FOREACH(list, elt, link)      \
-       for (elt = ISC_LIST_HEAD(list);         \
-            elt != NULL;                       \
+#define ISC_LIST_FOREACH(list, elt, link)                            \
+       for (typeof((list).head) elt = ISC_LIST_HEAD(list);           \
+            elt != NULL;                                             \
             elt = ISC_LIST_NEXT(elt, link))
 /* clang-format on */
 
 /* clang-format off */
-#define ISC_LIST_FOREACH_SAFE(list, elt, link, next)                                           \
-       for (elt = ISC_LIST_HEAD(list), next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL; \
-            elt != NULL;                                                                       \
-            elt = next, next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL)
+#define ISC_LIST_FOREACH_SAFE(list, elt, link)                             \
+       for (typeof((list).head) elt = ISC_LIST_HEAD(list),                \
+            elt##_next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL; \
+            elt != NULL;                                                  \
+            elt = elt##_next,                                             \
+             elt##_next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL)
 /* clang-format on */
 
 /* clang-format off */
-#define ISC_LIST_FOREACH_REV(list, elt, link)  \
-       for (elt = ISC_LIST_TAIL(list);         \
-            elt != NULL;                       \
+#define ISC_LIST_FOREACH_REV(list, elt, link)                        \
+       for (typeof((list).tail) elt = ISC_LIST_TAIL(list);           \
+            elt != NULL;                                             \
             elt = ISC_LIST_PREV(elt, link))
 /* clang-format on */
 
 /* clang-format off */
-#define ISC_LIST_FOREACH_REV_SAFE(list, elt, link, prev)                                               \
-       for (elt = ISC_LIST_TAIL(list), prev = (elt != NULL) ? ISC_LIST_PREV(elt, link) : NULL; \
-            elt != NULL;                                                                       \
-            elt = prev, prev = (elt != NULL) ? ISC_LIST_PREV(elt, link) : NULL)
+#define ISC_LIST_FOREACH_REV_SAFE(list, elt, link)                         \
+       for (typeof((list).tail) elt = ISC_LIST_TAIL(list),                \
+            elt##_prev = (elt != NULL) ? ISC_LIST_PREV(elt, link) : NULL; \
+            elt != NULL;                                                  \
+            elt = elt##_prev,                                             \
+             elt##_prev = (elt != NULL) ? ISC_LIST_PREV(elt, link) : NULL)
 /* clang-format on */
index 576e6b4150f2979d18fe69c338429883decdcefd..8222a85552be3196319002e8c4d2d0d1dcb8866a 100644 (file)
@@ -437,9 +437,7 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) {
        }
 
        for (size_t i = 0; i < ARRAY_SIZE(lcfg->channellists); i++) {
-               isc_logchannellist_t *item = NULL, *next = NULL;
-               ISC_LIST_FOREACH_SAFE (lcfg->channellists[i], item, link, next)
-               {
+               ISC_LIST_FOREACH_SAFE (lcfg->channellists[i], item, link) {
                        ISC_LIST_UNLINK(lcfg->channellists[i], item, link);
                        isc_mem_put(mctx, item, sizeof(*item));
                }
index dba623c7949d5da8ad64f72566ef511aea1357fe..75228db6c15c56fd69a71b1b4ac282d8582ba053 100644 (file)
@@ -6032,9 +6032,7 @@ message_clearrdataset(dns_message_t *msg, unsigned int attr) {
         * Clean up name lists by calling the rdataset disassociate function.
         */
        for (i = DNS_SECTION_ANSWER; i < DNS_SECTION_MAX; i++) {
-               dns_name_t *name, *next_name;
-               ISC_LIST_FOREACH_SAFE (msg->sections[i], name, link, next_name)
-               {
+               ISC_LIST_FOREACH_SAFE (msg->sections[i], name, link) {
                        rds = ISC_LIST_HEAD(name->list);
                        while (rds != NULL) {
                                next_rds = ISC_LIST_NEXT(rds, link);
@@ -11240,7 +11238,6 @@ query_glueanswer(query_ctx_t *qctx) {
        const dns_namelist_t *secs = qctx->client->message->sections;
        const dns_section_t section = DNS_SECTION_ADDITIONAL;
        dns_message_t *msg;
-       dns_rdataset_t *rdataset = NULL;
 
        if (!ISC_LIST_EMPTY(secs[DNS_SECTION_ANSWER]) ||
            qctx->client->message->rcode != dns_rcode_noerror ||
index 12350a317b3ce06e4c74c1bf3ef2c35d900bb11d..e5b1895b74bb39ae00d8545456104ca6924386a5 100644 (file)
@@ -732,7 +732,6 @@ ns_xfr_start(ns_client_t *client, dns_rdatatype_t reqtype) {
        rrstream_t *data_stream = NULL;
        rrstream_t *stream = NULL;
        dns_difftuple_t *current_soa_tuple = NULL;
-       dns_rdataset_t *soa_rdataset;
        dns_rdata_t soa_rdata = DNS_RDATA_INIT;
        bool have_soa = false;
        const char *mnemonic = NULL;