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.
This commit is contained in:
Ondřej Surý 2022-03-13 13:13:16 +01:00
parent f81b183c78
commit be47b2e5e4
25 changed files with 75 additions and 24 deletions

View file

@ -763,8 +763,9 @@ doshutdown(void) {
static void
maybeshutdown(void) {
/* when called from getinput, doshutdown might be already finished */
if (requestmgr == NULL)
if (requestmgr == NULL) {
return;
}
ddebug("Shutting down request manager");
dns_requestmgr_shutdown(requestmgr);

View file

@ -217,8 +217,9 @@ main(int argc, char *argv[]) {
if (len > 0) {
printf("0x");
}
for (j = 0; j < len; j++)
for (j = 0; j < len; j++) {
printf("%02x", idbuf[j]);
}
if (attr_template[2].ulValueLen > len) {
printf("...\n");
} else {

View file

@ -241,8 +241,9 @@ main(int argc, char *argv[]) {
if (len > 0) {
printf("0x");
}
for (j = 0; j < len; j++)
for (j = 0; j < len; j++) {
printf("%02x", idbuf[j]);
}
if (template[2].ulValueLen > len) {
printf("...");
}

View file

@ -160,8 +160,9 @@ main(int argc, char *argv[]) {
perror("malloc");
exit(1);
}
for (i = 0; i < count; i++)
for (i = 0; i < count; i++) {
hKey[i] = CK_INVALID_HANDLE;
}
/* Initialize the CRYPTOKI library */
if (lib_name != NULL) {

View file

@ -137,8 +137,9 @@ main(int argc, char *argv[]) {
perror("malloc");
exit(1);
}
for (i = 0; i < count; i++)
for (i = 0; i < count; i++) {
hSession[i] = CK_INVALID_HANDLE;
}
/* Initialize the CRYPTOKI library */
if (lib_name != NULL) {

View file

@ -233,8 +233,9 @@ main(int argc, char *argv[]) {
perror("malloc");
exit(1);
}
for (i = 0; i < count; i++)
for (i = 0; i < count; i++) {
hKey[i] = CK_INVALID_HANDLE;
}
/* Initialize the CRYPTOKI library */
if (lib_name != NULL) {

View file

@ -179,8 +179,9 @@ main(int argc, char *argv[]) {
perror("malloc");
exit(1);
}
for (i = 0; i < count; i++)
for (i = 0; i < count; i++) {
hKey[i] = CK_INVALID_HANDLE;
}
/* Initialize the CRYPTOKI library */
if (lib_name != NULL) {

View file

@ -132,8 +132,9 @@ main(int argc, char *argv[]) {
perror("malloc");
exit(1);
}
for (i = 0; i < count; i++)
for (i = 0; i < count; i++) {
hSession[i] = CK_INVALID_HANDLE;
}
/* Initialize the CRYPTOKI library */
if (lib_name != NULL) {

View file

@ -289,7 +289,9 @@ mysql_get_resultset(const char *zone, const char *record, const char *client,
break;
}
for (j = 0; mysql_ping((MYSQL *)dbi->dbconn) != 0 && j < 4; j++)
{
;
}
}
if (qres == 0) {

View file

@ -1108,8 +1108,9 @@ postgres_create(const char *dlzname, unsigned int argc, char *argv[],
/* if we cannot connect the first time, try 3 more times. */
for (j = 0;
PQstatus((PGconn *)dbi->dbconn) != CONNECTION_OK && j < 3;
j++)
j++) {
PQreset((PGconn *)dbi->dbconn);
}
/*
* if multi threaded, let user know which connection

View file

@ -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);

View file

@ -482,8 +482,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
@ -682,8 +683,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) {

View file

@ -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;
}

View file

@ -551,8 +551,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
@ -753,8 +754,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) {

View file

@ -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 */
}

View file

@ -396,8 +396,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);
@ -420,8 +421,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;
@ -459,8 +461,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;

View file

@ -211,6 +211,7 @@ pkcs11ecdsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
for (attr = pk11_attribute_first(ec); attr != NULL;
attr = pk11_attribute_next(ec, attr))
{
switch (attr->type) {
case CKA_EC_PARAMS:
INSIST(keyTemplate[5].type == attr->type);
@ -229,6 +230,7 @@ pkcs11ecdsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
keyTemplate[6].ulValueLen = attr->ulValueLen;
break;
}
}
pk11_ctx->object = CK_INVALID_HANDLE;
pk11_ctx->ontoken = false;
PK11_RET(pkcs_C_CreateObject,
@ -318,6 +320,7 @@ pkcs11ecdsa_verify(dst_context_t *dctx, const isc_region_t *sig) {
for (attr = pk11_attribute_first(ec); attr != NULL;
attr = pk11_attribute_next(ec, attr))
{
switch (attr->type) {
case CKA_EC_PARAMS:
INSIST(keyTemplate[5].type == attr->type);
@ -336,6 +339,7 @@ pkcs11ecdsa_verify(dst_context_t *dctx, const isc_region_t *sig) {
keyTemplate[6].ulValueLen = attr->ulValueLen;
break;
}
}
pk11_ctx->object = CK_INVALID_HANDLE;
pk11_ctx->ontoken = false;
PK11_RET(pkcs_C_CreateObject,
@ -605,6 +609,7 @@ pkcs11ecdsa_destroy(dst_key_t *key) {
for (attr = pk11_attribute_first(ec); attr != NULL;
attr = pk11_attribute_next(ec, attr))
{
switch (attr->type) {
case CKA_LABEL:
case CKA_ID:
@ -614,6 +619,7 @@ pkcs11ecdsa_destroy(dst_key_t *key) {
FREECURVE();
break;
}
}
if (ec->repr != NULL) {
memset(ec->repr, 0, ec->attrcnt * sizeof(*attr));
isc_mem_put(key->mctx, ec->repr, ec->attrcnt * sizeof(*attr));

View file

@ -180,6 +180,7 @@ pkcs11eddsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
for (attr = pk11_attribute_first(ec); attr != NULL;
attr = pk11_attribute_next(ec, attr))
{
switch (attr->type) {
case CKA_EC_PARAMS:
INSIST(keyTemplate[5].type == attr->type);
@ -198,6 +199,7 @@ pkcs11eddsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
keyTemplate[6].ulValueLen = attr->ulValueLen;
break;
}
}
pk11_ctx->object = CK_INVALID_HANDLE;
pk11_ctx->ontoken = false;
PK11_RET(pkcs_C_CreateObject,
@ -289,6 +291,7 @@ pkcs11eddsa_verify(dst_context_t *dctx, const isc_region_t *sig) {
for (attr = pk11_attribute_first(ec); attr != NULL;
attr = pk11_attribute_next(ec, attr))
{
switch (attr->type) {
case CKA_EC_PARAMS:
INSIST(keyTemplate[5].type == attr->type);
@ -307,6 +310,7 @@ pkcs11eddsa_verify(dst_context_t *dctx, const isc_region_t *sig) {
keyTemplate[6].ulValueLen = attr->ulValueLen;
break;
}
}
pk11_ctx->object = CK_INVALID_HANDLE;
pk11_ctx->ontoken = false;
PK11_RET(pkcs_C_CreateObject,
@ -577,6 +581,7 @@ pkcs11eddsa_destroy(dst_key_t *key) {
for (attr = pk11_attribute_first(ec); attr != NULL;
attr = pk11_attribute_next(ec, attr))
{
switch (attr->type) {
case CKA_LABEL:
case CKA_ID:
@ -586,6 +591,7 @@ pkcs11eddsa_destroy(dst_key_t *key) {
FREECURVE();
break;
}
}
if (ec->repr != NULL) {
memset(ec->repr, 0, ec->attrcnt * sizeof(*attr));
isc_mem_put(key->mctx, ec->repr, ec->attrcnt * sizeof(*attr));

View file

@ -140,6 +140,7 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) {
for (attr = pk11_attribute_first(rsa); attr != NULL;
attr = pk11_attribute_next(rsa, attr))
{
switch (attr->type) {
case CKA_MODULUS:
INSIST(keyTemplate[6].type == attr->type);
@ -206,6 +207,7 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) {
keyTemplate[13].ulValueLen = attr->ulValueLen;
break;
}
}
pk11_ctx->object = CK_INVALID_HANDLE;
pk11_ctx->ontoken = false;
PK11_RET(pkcs_C_CreateObject,
@ -776,6 +778,7 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
for (attr = pk11_attribute_first(rsa); attr != NULL;
attr = pk11_attribute_next(rsa, attr))
{
switch (attr->type) {
case CKA_MODULUS:
INSIST(keyTemplate[6].type == attr->type);
@ -842,6 +845,7 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
keyTemplate[13].ulValueLen = attr->ulValueLen;
break;
}
}
pk11_ctx->object = CK_INVALID_HANDLE;
pk11_ctx->ontoken = false;
PK11_RET(pkcs_C_CreateObject,
@ -1259,6 +1263,7 @@ pkcs11rsa_destroy(dst_key_t *key) {
for (attr = pk11_attribute_first(rsa); attr != NULL;
attr = pk11_attribute_next(rsa, attr))
{
switch (attr->type) {
case CKA_LABEL:
case CKA_ID:
@ -1278,6 +1283,7 @@ pkcs11rsa_destroy(dst_key_t *key) {
}
break;
}
}
if (rsa->repr != NULL) {
isc_safe_memwipe(rsa->repr, rsa->attrcnt * sizeof(*attr));
isc_mem_put(key->mctx, rsa->repr, rsa->attrcnt * sizeof(*attr));
@ -1301,6 +1307,7 @@ pkcs11rsa_todns(const dst_key_t *key, isc_buffer_t *data) {
for (attr = pk11_attribute_first(rsa); attr != NULL;
attr = pk11_attribute_next(rsa, attr))
{
switch (attr->type) {
case CKA_PUBLIC_EXPONENT:
exponent = (CK_BYTE *)attr->pValue;
@ -1311,6 +1318,7 @@ pkcs11rsa_todns(const dst_key_t *key, isc_buffer_t *data) {
mod_bytes = (unsigned int)attr->ulValueLen;
break;
}
}
REQUIRE((exponent != NULL) && (modulus != NULL));
isc_buffer_availableregion(data, &r);
@ -1440,6 +1448,7 @@ pkcs11rsa_tofile(const dst_key_t *key, const char *directory) {
for (attr = pk11_attribute_first(rsa); attr != NULL;
attr = pk11_attribute_next(rsa, attr))
{
switch (attr->type) {
case CKA_MODULUS:
modulus = attr;
@ -1466,6 +1475,7 @@ pkcs11rsa_tofile(const dst_key_t *key, const char *directory) {
iqmp = attr;
break;
}
}
if ((modulus == NULL) || (exponent == NULL)) {
return (DST_R_NULLKEY);
}

View file

@ -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);
}

View file

@ -291,7 +291,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));
}

View file

@ -1463,9 +1463,10 @@ dump_msg(struct msghdr *msg) {
printf("\tname %p, namelen %ld\n", msg->msg_name,
(long)msg->msg_namelen);
printf("\tiov %p, iovlen %ld\n", msg->msg_iov, (long)msg->msg_iovlen);
for (i = 0; i < (unsigned int)msg->msg_iovlen; i++)
for (i = 0; i < (unsigned int)msg->msg_iovlen; i++) {
printf("\t\t%u\tbase %p, len %ld\n", i,
msg->msg_iov[i].iov_base, (long)msg->msg_iov[i].iov_len);
}
printf("\tcontrol %p, controllen %ld\n", msg->msg_control,
(long)msg->msg_controllen);
}

View file

@ -256,7 +256,9 @@ isc_dir_createunique(char *templet) {
*/
for (x = templet + strlen(templet) - 1; *x == 'X' && x >= templet;
x--, pid /= 10)
{
*x = pid % 10 + '0';
}
x++; /* Set x to start of ex-Xs. */

View file

@ -387,8 +387,9 @@ internal_current6(isc_interfaceiter_t *iter) {
snprintf(iter->current.name, sizeof(iter->current.name),
"TCP/IPv6 Interface %u", iter->pos6 + 1);
for (i = 0; i < 16; i++)
for (i = 0; i < 16; i++) {
iter->current.netmask.type.in6.s6_addr[i] = 0xff;
}
iter->current.netmask.family = AF_INET6;
if (IN6_IS_ADDR_LOOPBACK(&iter->current.address.type.in6)) {
iter->v6loop = true;

View file

@ -1028,9 +1028,10 @@ dump_msg(struct msghdr *msg, isc_socket_t *sock) {
printf("MSGHDR %p, Socket #: %Iu\n", msg, sock->fd);
printf("\tname %p, namelen %d\n", msg->msg_name, msg->msg_namelen);
printf("\tiov %p, iovlen %d\n", msg->msg_iov, msg->msg_iovlen);
for (i = 0; i < (unsigned int)msg->msg_iovlen; i++)
for (i = 0; i < (unsigned int)msg->msg_iovlen; i++) {
printf("\t\t%u\tbase %p, len %u\n", i, msg->msg_iov[i].buf,
msg->msg_iov[i].len);
}
}
#endif /* if defined(ISC_SOCKET_DEBUG) */