SonarCloud: fix some minor codesmells

pull/617/head
Brad House 1 year ago
parent 0cc570eabe
commit 0bc2eadecd
  1. 84
      src/lib/ares__buf.c
  2. 7
      src/lib/ares_dns_write.c
  3. 4
      src/lib/ares_update_servers.c

@ -887,61 +887,73 @@ static ares_status_t ares__buf_append_str(ares__buf_t *buf, const char *str)
return ares__buf_append(buf, (const unsigned char *)str, ares_strlen(str)); return ares__buf_append(buf, (const unsigned char *)str, ares_strlen(str));
} }
ares_status_t ares__buf_hexdump(ares__buf_t *buf, const unsigned char *data, static ares_status_t ares__buf_hexdump_line(ares__buf_t *buf,
size_t len) size_t idx,
const unsigned char *data,
size_t len)
{ {
size_t i; size_t i;
ares_status_t status; ares_status_t status;
/* Each line is 16 bytes */
for (i = 0; i < len; i += 16) {
size_t j;
/* Address */ /* Address */
status = ares__buf_append_num_hex(buf, i, 6); status = ares__buf_append_num_hex(buf, idx, 6);
if (status != ARES_SUCCESS) {
return status;
}
/* | */
status = ares__buf_append_str(buf, " | ");
if (status != ARES_SUCCESS) {
return status;
}
for (i = 0; i < 16; i++) {
if (i >= len) {
status = ares__buf_append_str(buf, " ");
} else {
status = ares__buf_append_num_hex(buf, data[i], 2);
}
if (status != ARES_SUCCESS) { if (status != ARES_SUCCESS) {
return status; return status;
} }
/* | */ status = ares__buf_append_byte(buf, ' ');
status = ares__buf_append_str(buf, " | ");
if (status != ARES_SUCCESS) { if (status != ARES_SUCCESS) {
return status; return status;
} }
}
for (j = i; j < i + 16; j++) { /* | */
if (j >= len) { status = ares__buf_append_str(buf, " | ");
status = ares__buf_append_str(buf, " "); if (status != ARES_SUCCESS) {
} else { return status;
status = ares__buf_append_num_hex(buf, data[j], 2); }
}
if (status != ARES_SUCCESS) {
return status;
}
status = ares__buf_append_byte(buf, ' '); for (i = 0; i < 16; i++) {
if (status != ARES_SUCCESS) { if (i >= len) {
return status; break;
}
} }
status =
/* | */ ares__buf_append_byte(buf, ares__isprint(data[i]) ? data[i] : '.');
status = ares__buf_append_str(buf, " | ");
if (status != ARES_SUCCESS) { if (status != ARES_SUCCESS) {
return status; return status;
} }
}
for (j = i; j < i + 16; j++) { return ares__buf_append_byte(buf, '\n');
if (j >= len) { }
break;
}
status =
ares__buf_append_byte(buf, ares__isprint(data[j]) ? data[j] : '.');
if (status != ARES_SUCCESS) {
return status;
}
}
ares__buf_append_byte(buf, '\n'); ares_status_t ares__buf_hexdump(ares__buf_t *buf, const unsigned char *data,
size_t len)
{
size_t i;
/* Each line is 16 bytes */
for (i = 0; i < len; i += 16) {
ares_status_t status;
status = ares__buf_hexdump_line(buf, i, data + i, len - i);
if (status != ARES_SUCCESS)
return status;
} }
return ARES_SUCCESS; return ARES_SUCCESS;

@ -192,7 +192,12 @@ static ares_status_t ares_dns_write_rr_str(ares__buf_t *buf,
ares_status_t status; ares_status_t status;
str = ares_dns_rr_get_str(rr, key); str = ares_dns_rr_get_str(rr, key);
if (str == NULL || (len = ares_strlen(str)) > 255) { if (str == NULL) {
return ARES_EFORMERR;
}
len = ares_strlen(str);
if (len > 255) {
return ARES_EFORMERR; return ARES_EFORMERR;
} }

@ -505,8 +505,8 @@ static void ares__servers_remove_stale(ares_channel_t *channel,
ares__slist_node_t *snode = ares__slist_node_first(channel->servers); ares__slist_node_t *snode = ares__slist_node_first(channel->servers);
while (snode != NULL) { while (snode != NULL) {
ares__slist_node_t *snext = ares__slist_node_next(snode); ares__slist_node_t *snext = ares__slist_node_next(snode);
struct server_state *server = ares__slist_node_val(snode); const struct server_state *server = ares__slist_node_val(snode);
if (!ares__server_in_newconfig(server, srvlist)) { if (!ares__server_in_newconfig(server, srvlist)) {
/* This will clean up all server state via the destruction callback and /* This will clean up all server state via the destruction callback and
* move any queries to new servers */ * move any queries to new servers */

Loading…
Cancel
Save