Commit 056e133c authored by Ondřej Surý's avatar Ondřej Surý

Use clang-tidy to add curly braces around one-line statements

The command used to reformat the files in this commit was:

./util/run-clang-tidy \
	-clang-tidy-binary clang-tidy-11
	-clang-apply-replacements-binary clang-apply-replacements-11 \
	-checks=-*,readability-braces-around-statements \
	-j 9 \
	-fix \
	-format \
	-style=file \
	-quiet
clang-format -i --style=format $(git ls-files '*.c' '*.h')
uncrustify -c .uncrustify.cfg --replace --no-backup $(git ls-files '*.c' '*.h')
clang-format -i --style=format $(git ls-files '*.c' '*.h')
parent d14bb713
Pipeline #33983 passed with stages
in 20 minutes and 12 seconds
......@@ -17,7 +17,7 @@
#ifdef _WIN32
#include <Winsock2.h>
#endif
#endif /* ifdef _WIN32 */
#include <isc/buffer.h>
#include <isc/log.h>
......@@ -54,11 +54,11 @@
#ifndef CHECK_SIBLING
#define CHECK_SIBLING 1
#endif
#endif /* ifndef CHECK_SIBLING */
#ifndef CHECK_LOCAL
#define CHECK_LOCAL 1
#endif
#endif /* ifndef CHECK_LOCAL */
#define CHECK(r) \
do { \
......@@ -85,17 +85,17 @@ bool nomerge = true;
bool docheckmx = true;
bool dochecksrv = true;
bool docheckns = true;
#else
#else /* if CHECK_LOCAL */
bool docheckmx = false;
bool dochecksrv = false;
bool docheckns = false;
#endif
#endif /* if CHECK_LOCAL */
dns_zoneopt_t zone_options = DNS_ZONEOPT_CHECKNS | DNS_ZONEOPT_CHECKMX |
DNS_ZONEOPT_MANYERRORS | DNS_ZONEOPT_CHECKNAMES |
DNS_ZONEOPT_CHECKINTEGRITY |
#if CHECK_SIBLING
DNS_ZONEOPT_CHECKSIBLING |
#endif
#endif /* if CHECK_SIBLING */
DNS_ZONEOPT_CHECKWILDCARD |
DNS_ZONEOPT_WARNMXCNAME | DNS_ZONEOPT_WARNSRVCNAME;
......@@ -130,8 +130,9 @@ add(char *key, int value)
if (symtab == NULL) {
result = isc_symtab_create(sym_mctx, 100, freekey, sym_mctx,
false, &symtab);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return;
}
}
key = isc_mem_strdup(sym_mctx, key);
......@@ -139,8 +140,9 @@ add(char *key, int value)
symvalue.as_pointer = NULL;
result = isc_symtab_define(symtab, key, value, symvalue,
isc_symexists_reject);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
isc_mem_free(sym_mctx, key);
}
}
static bool
......@@ -148,12 +150,14 @@ logged(char *key, int value)
{
isc_result_t result;
if (symtab == NULL)
if (symtab == NULL) {
return (false);
}
result = isc_symtab_lookup(symtab, key, value, NULL);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
return (true);
}
return (false);
}
......@@ -178,8 +182,9 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
REQUIRE(aaaa == NULL || !dns_rdataset_isassociated(aaaa) ||
aaaa->type == dns_rdatatype_aaaa);
if (a == NULL || aaaa == NULL)
if (a == NULL || aaaa == NULL) {
return (answer);
}
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
......@@ -206,8 +211,9 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
*/
cur = ai;
while (cur != NULL && cur->ai_canonname == NULL &&
cur->ai_next != NULL)
cur->ai_next != NULL) {
cur = cur->ai_next;
}
if (cur != NULL && cur->ai_canonname != NULL &&
strcasecmp(cur->ai_canonname, namebuf) != 0 &&
!logged(namebuf, ERR_IS_CNAME)) {
......@@ -223,7 +229,7 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
case EAI_NONAME:
#if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME)
case EAI_NODATA:
#endif
#endif /* if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME) */
if (!logged(namebuf, ERR_NO_ADDRESSES)) {
dns_zone_log(zone, ISC_LOG_ERROR,
"%s/NS '%s' (out of zone) "
......@@ -247,15 +253,17 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
/*
* Check that all glue records really exist.
*/
if (!dns_rdataset_isassociated(a))
if (!dns_rdataset_isassociated(a)) {
goto checkaaaa;
}
result = dns_rdataset_first(a);
while (result == ISC_R_SUCCESS) {
dns_rdataset_current(a, &rdata);
match = false;
for (cur = ai; cur != NULL; cur = cur->ai_next) {
if (cur->ai_family != AF_INET)
if (cur->ai_family != AF_INET) {
continue;
}
ptr = &((struct sockaddr_in *)(cur->ai_addr))->sin_addr;
if (memcmp(ptr, rdata.data, rdata.length) == 0) {
match = true;
......@@ -278,15 +286,17 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
}
checkaaaa:
if (!dns_rdataset_isassociated(aaaa))
if (!dns_rdataset_isassociated(aaaa)) {
goto checkmissing;
}
result = dns_rdataset_first(aaaa);
while (result == ISC_R_SUCCESS) {
dns_rdataset_current(aaaa, &rdata);
match = false;
for (cur = ai; cur != NULL; cur = cur->ai_next) {
if (cur->ai_family != AF_INET6)
if (cur->ai_family != AF_INET6) {
continue;
}
ptr = &((struct sockaddr_in6 *)(cur->ai_addr))
->sin6_addr;
if (memcmp(ptr, rdata.data, rdata.length) == 0) {
......@@ -333,14 +343,17 @@ checkmissing:
continue;
}
match = false;
if (dns_rdataset_isassociated(rdataset))
if (dns_rdataset_isassociated(rdataset)) {
result = dns_rdataset_first(rdataset);
else
} else {
result = ISC_R_FAILURE;
}
while (result == ISC_R_SUCCESS && !match) {
dns_rdataset_current(rdataset, &rdata);
if (memcmp(ptr, rdata.data, rdata.length) == 0)
if (memcmp(ptr, rdata.data, rdata.length) ==
0) {
match = true;
}
dns_rdata_reset(&rdata);
result = dns_rdataset_next(rdataset);
}
......@@ -357,8 +370,9 @@ checkmissing:
missing_glue = true;
}
}
if (missing_glue)
if (missing_glue) {
add(namebuf, ERR_MISSING_GLUE);
}
}
freeaddrinfo(ai);
return (answer);
......@@ -399,12 +413,14 @@ checkmx(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
*/
cur = ai;
while (cur != NULL && cur->ai_canonname == NULL &&
cur->ai_next != NULL)
cur->ai_next != NULL) {
cur = cur->ai_next;
}
if (cur != NULL && cur->ai_canonname != NULL &&
strcasecmp(cur->ai_canonname, namebuf) != 0) {
if ((zone_options & DNS_ZONEOPT_WARNMXCNAME) != 0)
if ((zone_options & DNS_ZONEOPT_WARNMXCNAME) != 0) {
level = ISC_LOG_WARNING;
}
if ((zone_options & DNS_ZONEOPT_IGNOREMXCNAME) == 0) {
if (!logged(namebuf, ERR_IS_MXCNAME)) {
dns_zone_log(zone, level,
......@@ -415,8 +431,9 @@ checkmx(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
cur->ai_canonname);
add(namebuf, ERR_IS_MXCNAME);
}
if (level == ISC_LOG_ERROR)
if (level == ISC_LOG_ERROR) {
answer = false;
}
}
}
freeaddrinfo(ai);
......@@ -425,7 +442,7 @@ checkmx(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
case EAI_NONAME:
#if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME)
case EAI_NODATA:
#endif
#endif /* if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME) */
if (!logged(namebuf, ERR_NO_ADDRESSES)) {
dns_zone_log(zone, ISC_LOG_ERROR,
"%s/MX '%s' (out of zone) "
......@@ -482,12 +499,14 @@ checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
*/
cur = ai;
while (cur != NULL && cur->ai_canonname == NULL &&
cur->ai_next != NULL)
cur->ai_next != NULL) {
cur = cur->ai_next;
}
if (cur != NULL && cur->ai_canonname != NULL &&
strcasecmp(cur->ai_canonname, namebuf) != 0) {
if ((zone_options & DNS_ZONEOPT_WARNSRVCNAME) != 0)
if ((zone_options & DNS_ZONEOPT_WARNSRVCNAME) != 0) {
level = ISC_LOG_WARNING;
}
if ((zone_options & DNS_ZONEOPT_IGNORESRVCNAME) == 0) {
if (!logged(namebuf, ERR_IS_SRVCNAME)) {
dns_zone_log(zone, level,
......@@ -498,8 +517,9 @@ checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
cur->ai_canonname);
add(namebuf, ERR_IS_SRVCNAME);
}
if (level == ISC_LOG_ERROR)
if (level == ISC_LOG_ERROR) {
answer = false;
}
}
}
freeaddrinfo(ai);
......@@ -508,7 +528,7 @@ checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
case EAI_NONAME:
#if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME)
case EAI_NODATA:
#endif
#endif /* if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME) */
if (!logged(namebuf, ERR_NO_ADDRESSES)) {
dns_zone_log(zone, ISC_LOG_ERROR,
"%s/SRV '%s' (out of zone) "
......@@ -584,8 +604,9 @@ check_ttls(dns_zone_t *zone, dns_ttl_t maxttl)
for (result = dns_dbiterator_first(dbiter); result == ISC_R_SUCCESS;
result = dns_dbiterator_next(dbiter)) {
result = dns_dbiterator_current(dbiter, &node, name);
if (result == DNS_R_NEWORIGIN)
if (result == DNS_R_NEWORIGIN) {
result = ISC_R_SUCCESS;
}
CHECK(result);
CHECK(dns_db_allrdatasets(db, node, version, 0, &rdsiter));
......@@ -614,28 +635,35 @@ check_ttls(dns_zone_t *zone, dns_ttl_t maxttl)
}
dns_rdataset_disassociate(&rdataset);
}
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
result = ISC_R_SUCCESS;
}
CHECK(result);
dns_rdatasetiter_destroy(&rdsiter);
dns_db_detachnode(db, &node);
}
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
result = ISC_R_SUCCESS;
}
cleanup:
if (node != NULL)
if (node != NULL) {
dns_db_detachnode(db, &node);
if (rdsiter != NULL)
}
if (rdsiter != NULL) {
dns_rdatasetiter_destroy(&rdsiter);
if (dbiter != NULL)
}
if (dbiter != NULL) {
dns_dbiterator_destroy(&dbiter);
if (version != NULL)
}
if (version != NULL) {
dns_db_closeversion(db, &version, false);
if (db != NULL)
}
if (db != NULL) {
dns_db_detach(&db);
}
return (result);
}
......@@ -656,9 +684,10 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
REQUIRE(zonep == NULL || *zonep == NULL);
if (debug)
if (debug) {
fprintf(stderr, "loading \"%s\" from \"%s\" class \"%s\"\n",
zonename, filename, classname);
}
CHECK(dns_zone_create(&zone, mctx));
......@@ -672,8 +701,9 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
dns_zone_setdbtype(zone, 1, (const char *const *)dbtype);
CHECK(dns_zone_setfile(zone, filename, fileformat,
&dns_master_style_default));
if (journal != NULL)
if (journal != NULL) {
CHECK(dns_zone_setjournal(zone, journal));
}
DE_CONST(classname, region.base);
region.length = strlen(classname);
......@@ -685,12 +715,15 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
dns_zone_setmaxttl(zone, maxttl);
if (docheckmx)
if (docheckmx) {
dns_zone_setcheckmx(zone, checkmx);
if (docheckns)
}
if (docheckns) {
dns_zone_setcheckns(zone, checkns);
if (dochecksrv)
}
if (dochecksrv) {
dns_zone_setchecksrv(zone, checksrv);
}
CHECK(dns_zone_load(zone, false));
......@@ -708,8 +741,9 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
}
cleanup:
if (zone != NULL)
if (zone != NULL) {
dns_zone_detach(&zone);
}
return (result);
}
......@@ -726,11 +760,12 @@ dump_zone(const char *zonename, dns_zone_t *zone, const char *filename,
flags = (fileformat == dns_masterformat_text) ? "w" : "wb";
if (debug) {
if (filename != NULL && strcmp(filename, "-") != 0)
if (filename != NULL && strcmp(filename, "-") != 0) {
fprintf(stderr, "dumping \"%s\" to \"%s\"\n", zonename,
filename);
else
} else {
fprintf(stderr, "dumping \"%s\"\n", zonename);
}
}
if (filename != NULL && strcmp(filename, "-") != 0) {
......@@ -747,8 +782,9 @@ dump_zone(const char *zonename, dns_zone_t *zone, const char *filename,
result = dns_zone_dumptostream(zone, output, fileformat, style,
rawversion);
if (output != stdout)
if (output != stdout) {
(void)isc_stdio_close(output);
}
return (result);
}
......@@ -775,4 +811,4 @@ DestroySockets(void)
{
WSACleanup();
}
#endif
#endif /* ifdef _WIN32 */
......@@ -45,7 +45,7 @@ void
InitSockets(void);
void
DestroySockets(void);
#endif
#endif /* ifdef _WIN32 */
extern int debug;
extern const char * journal;
......@@ -57,4 +57,4 @@ extern dns_zoneopt_t zone_options;
ISC_LANG_ENDDECLS
#endif
#endif /* ifndef CHECK_TOOL_H */
......@@ -101,10 +101,12 @@ get_maps(const cfg_obj_t **maps, const char *name, const cfg_obj_t **obj)
{
int i;
for (i = 0;; i++) {
if (maps[i] == NULL)
if (maps[i] == NULL) {
return (false);
if (cfg_map_get(maps[i], name, obj) == ISC_R_SUCCESS)
}
if (cfg_map_get(maps[i], name, obj) == ISC_R_SUCCESS) {
return (true);
}
}
}
......@@ -119,12 +121,14 @@ get_checknames(const cfg_obj_t **maps, const cfg_obj_t **obj)
int i;
for (i = 0;; i++) {
if (maps[i] == NULL)
if (maps[i] == NULL) {
return (false);
}
checknames = NULL;
result = cfg_map_get(maps[i], "check-names", &checknames);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
continue;
}
if (checknames != NULL && !cfg_obj_islist(checknames)) {
*obj = checknames;
return (true);
......@@ -153,18 +157,21 @@ configure_hint(const char *zfile, const char *zclass, isc_mem_t *mctx)
dns_rdataclass_t rdclass;
isc_textregion_t r;
if (zfile == NULL)
if (zfile == NULL) {
return (ISC_R_FAILURE);
}
DE_CONST(zclass, r.base);
r.length = strlen(zclass);
result = dns_rdataclass_fromtext(&rdclass, &r);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result