From ff2249884948e309ade3a3abe83968a214e3e63f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Sun, 13 Mar 2022 13:05:27 +0100 Subject: [PATCH] Add couple missing braces around single-line statements The clang-format-15 has new option InsertBraces that could add missing branches around single line statements. Use that to our advantage without switching to not-yet-released LLVM version to add missing braces in couple of places. --- bin/dig/dig.c | 9 ++++++--- contrib/dlz/example/dlz_example.c | 3 ++- contrib/dlz/modules/mysql/dlz_mysql_dynamic.c | 6 ++++-- contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c | 3 ++- contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c | 6 ++++-- contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c | 3 ++- lib/dns/openssleddsa_link.c | 9 ++++++--- lib/dns/rdata/generic/gpos_27.c | 3 ++- lib/dns/rdata/generic/hip_55.c | 4 +++- lib/isc/tests/mem_test.c | 3 ++- 10 files changed, 33 insertions(+), 16 deletions(-) diff --git a/bin/dig/dig.c b/bin/dig/dig.c index fbaf7e1d23..4421df9d5d 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -490,10 +490,12 @@ dns64prefix_answer(dns_message_t *msg, isc_buffer_t *buf) { } result = dns_dns64_findprefix(rdataset, prefix, &count); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (count > 10) + } + if (count > 10) { count = 10; + } for (i = 0; i < count; i++) { result = isc_netaddr_totext(&prefix[i].addr, buf); if (result != ISC_R_SUCCESS) { @@ -903,8 +905,9 @@ repopulate_buffer: check_result(result, "dns_message_sectiontotext"); } else if (dns64prefix) { result = dns64prefix_answer(msg, buf); - if (result == ISC_R_NOSPACE) + if (result == ISC_R_NOSPACE) { goto buftoosmall; + } check_result(result, "dns64prefix_answer"); } else { result = short_answer(msg, flags, buf, query); diff --git a/contrib/dlz/example/dlz_example.c b/contrib/dlz/example/dlz_example.c index 1ad12ce01a..8be3afb162 100644 --- a/contrib/dlz/example/dlz_example.c +++ b/contrib/dlz/example/dlz_example.c @@ -474,8 +474,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, } if (strcmp(name, "too-long") == 0) { - for (i = 0; i < 511; i++) + for (i = 0; i < 511; i++) { buf[i] = 'x'; + } buf[i] = '\0'; found = true; result = state->putrr(lookup, "TXT", 0, buf); diff --git a/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c b/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c index d56895d10c..b31b687f0a 100644 --- a/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c +++ b/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c @@ -468,8 +468,9 @@ mysql_process_rs(mysql_instance_t *db, dns_sdlzlookup_t *lookup, * ones together. figure out how long to make * string. */ - for (j = 2; j < fields; j++) + for (j = 2; j < fields; j++) { len += strlen(safeGet(row[j])) + 1; + } /* * allocate string memory, allow for NULL to @@ -668,8 +669,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) { * more than 4 fields, concatenate the last * ones together. */ - for (j = 3; j < fields; j++) + for (j = 3; j < fields; j++) { len += strlen(safeGet(row[j])) + 1; + } tmpString = malloc(len + 1); if (tmpString == NULL) { diff --git a/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c b/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c index d0204c6b99..ec6a494dd8 100644 --- a/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c +++ b/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c @@ -706,8 +706,9 @@ make_notify(const char *zone, int *packetlen) { /* Make the question into labels */ j = 12; while (packet[j]) { - for (i = j + 1; packet[i] != '\0' && packet[i] != '.'; i++) + for (i = j + 1; packet[i] != '\0' && packet[i] != '.'; i++) { ; + } packet[j] = i - j - 1; j = i; } diff --git a/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c b/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c index 70358b329e..1ae2056125 100644 --- a/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c +++ b/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c @@ -537,8 +537,9 @@ sqlite3_process_rs(sqlite3_instance_t *db, dns_sdlzlookup_t *lookup, * ones together. figure out how long to make * string. */ - for (j = 2; j < fields; j++) + for (j = 2; j < fields; j++) { len += strlen(safeGet(row[j])) + 1; + } /* * allocate string memory, allow for NULL to @@ -739,8 +740,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) { * more than 4 fields, concatenate the last * ones together. */ - for (j = 3; j < fields; j++) + for (j = 3; j < fields; j++) { len += strlen(safeGet(row[j])) + 1; + } tmpString = malloc(len + 1); if (tmpString == NULL) { diff --git a/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c b/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c index d108796c00..1090d780f0 100644 --- a/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c +++ b/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c @@ -585,7 +585,7 @@ fnmatch(const char *pattern, const char *string, int flags) { char *newp; char c, test; - for (stringstart = string;;) + for (stringstart = string;;) { switch (c = *pattern++) { case EOS: if ((flags & FNM_LEADING_DIR) && *string == '/') { @@ -698,6 +698,7 @@ fnmatch(const char *pattern, const char *string, int flags) { string++; break; } + } /* NOTREACHED */ } diff --git a/lib/dns/openssleddsa_link.c b/lib/dns/openssleddsa_link.c index 3a38a77e4c..2f599647da 100644 --- a/lib/dns/openssleddsa_link.c +++ b/lib/dns/openssleddsa_link.c @@ -394,8 +394,9 @@ openssleddsa_todns(const dst_key_t *key, isc_buffer_t *data) { return (ISC_R_NOSPACE); } - if (EVP_PKEY_get_raw_public_key(pkey, r.base, &len) != 1) + if (EVP_PKEY_get_raw_public_key(pkey, r.base, &len) != 1) { return (dst__openssl_toresult(ISC_R_FAILURE)); + } isc_buffer_add(data, len); return (ISC_R_SUCCESS); @@ -418,8 +419,9 @@ openssleddsa_fromdns(dst_key_t *key, isc_buffer_t *data) { len = r.length; ret = raw_key_to_ossl(key->key_alg, 0, r.base, &len, &pkey); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return ret; + } isc_buffer_forward(data, len); key->keydata.pkey = pkey; @@ -457,8 +459,9 @@ openssleddsa_tofile(const dst_key_t *key, const char *directory) { } buf = isc_mem_get(key->mctx, len); if (EVP_PKEY_get_raw_private_key(key->keydata.pkey, buf, - &len) != 1) + &len) != 1) { DST_RET(dst__openssl_toresult(ISC_R_FAILURE)); + } priv.elements[i].tag = TAG_EDDSA_PRIVATEKEY; priv.elements[i].length = len; priv.elements[i].data = buf; diff --git a/lib/dns/rdata/generic/gpos_27.c b/lib/dns/rdata/generic/gpos_27.c index 96cdd501e4..2a7245068f 100644 --- a/lib/dns/rdata/generic/gpos_27.c +++ b/lib/dns/rdata/generic/gpos_27.c @@ -72,8 +72,9 @@ fromwire_gpos(ARGS_FROMWIRE) { UNUSED(rdclass); UNUSED(options); - for (i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { RETERR(txt_fromwire(source, target)); + } return (ISC_R_SUCCESS); } diff --git a/lib/dns/rdata/generic/hip_55.c b/lib/dns/rdata/generic/hip_55.c index 314bf1881a..2df63ffcc1 100644 --- a/lib/dns/rdata/generic/hip_55.c +++ b/lib/dns/rdata/generic/hip_55.c @@ -290,7 +290,9 @@ fromstruct_hip(ARGS_FROMSTRUCT) { myhip = *hip; for (result = dns_rdata_hip_first(&myhip); result == ISC_R_SUCCESS; result = dns_rdata_hip_next(&myhip)) - /* empty */; + { + /* initialize the names */ + } return (mem_tobuffer(target, hip->servers, hip->servers_len)); } diff --git a/lib/isc/tests/mem_test.c b/lib/isc/tests/mem_test.c index 524f9b1ff4..5f382a3819 100644 --- a/lib/isc/tests/mem_test.c +++ b/lib/isc/tests/mem_test.c @@ -473,8 +473,9 @@ mem_thread(isc_threadarg_t arg) { isc_mem_t *mctx = (isc_mem_t *)arg; void *items[NUM_ITEMS]; size_t size = atomic_load(&mem_size); - while (!atomic_compare_exchange_weak(&mem_size, &size, size / 2)) + while (!atomic_compare_exchange_weak(&mem_size, &size, size / 2)) { ; + } for (int i = 0; i < ITERS; i++) { for (int j = 0; j < NUM_ITEMS; j++) {