2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

switch to ISC_LIST_FOREACH everywhere

the pattern `for (x = ISC_LIST_HEAD(...); x != NULL; ISC_LIST_NEXT(...)`
has been changed to `ISC_LIST_FOREACH` throughout BIND, except in a few
cases where the change would be excessively complex.

in most cases this was a straightforward change. in some places,
however, the list element variable was referenced after the loop
ended, and the code was refactored to avoid this necessity.

also, because `ISC_LIST_FOREACH` uses typeof(list.head) to declare
the list elements, compilation failures can occur if the list object
has a `const` qualifier.  some `const` qualifiers have been removed
from function parameters to avoid this problem, and where that was not
possible, `UNCONST` was used.
This commit is contained in:
Evan Hunt
2025-03-20 22:25:56 -07:00
parent 5cff8f9017
commit 522ca7bb54
66 changed files with 766 additions and 1786 deletions

View File

@@ -170,8 +170,6 @@ dns_diff_size(const dns_diff_t *diff) {
void
dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuplep) {
dns_difftuple_t *ot, *next_ot;
REQUIRE(DNS_DIFF_VALID(diff));
REQUIRE(DNS_DIFFTUPLE_VALID(*tuplep));
@@ -187,8 +185,7 @@ dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuplep) {
* the one we are doing, there must be a programming
* error. We report it but try to continue anyway.
*/
for (ot = ISC_LIST_HEAD(diff->tuples); ot != NULL; ot = next_ot) {
next_ot = ISC_LIST_NEXT(ot, link);
ISC_LIST_FOREACH_SAFE (diff->tuples, ot, link) {
if (dns_name_caseequal(&ot->name, &(*tuplep)->name) &&
dns_rdata_compare(&ot->rdata, &(*tuplep)->rdata) == 0 &&
ot->ttl == (*tuplep)->ttl)
@@ -619,13 +616,10 @@ isc_result_t
dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare) {
unsigned int length = 0;
unsigned int i;
dns_difftuple_t **v;
dns_difftuple_t *p;
dns_difftuple_t **v = NULL;
REQUIRE(DNS_DIFF_VALID(diff));
for (p = ISC_LIST_HEAD(diff->tuples); p != NULL;
p = ISC_LIST_NEXT(p, link))
{
ISC_LIST_FOREACH (diff->tuples, p, link) {
length++;
}
if (length == 0) {
@@ -633,7 +627,7 @@ dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare) {
}
v = isc_mem_cget(diff->mctx, length, sizeof(dns_difftuple_t *));
for (i = 0; i < length; i++) {
p = ISC_LIST_HEAD(diff->tuples);
dns_difftuple_t *p = ISC_LIST_HEAD(diff->tuples);
v[i] = p;
ISC_LIST_UNLINK(diff->tuples, p, link);
}
@@ -671,9 +665,8 @@ diff_tuple_tordataset(dns_difftuple_t *t, dns_rdata_t *rdata,
}
isc_result_t
dns_diff_print(const dns_diff_t *diff, FILE *file) {
dns_diff_print(dns_diff_t *diff, FILE *file) {
isc_result_t result;
dns_difftuple_t *t;
char *mem = NULL;
unsigned int size = 2048;
const char *op = NULL;
@@ -682,9 +675,7 @@ dns_diff_print(const dns_diff_t *diff, FILE *file) {
mem = isc_mem_get(diff->mctx, size);
for (t = ISC_LIST_HEAD(diff->tuples); t != NULL;
t = ISC_LIST_NEXT(t, link))
{
ISC_LIST_FOREACH (diff->tuples, t, link) {
isc_buffer_t buf;
isc_region_t r;