SonarCloud: fix some minor codesmells

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

@ -887,17 +887,16 @@ 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));
}
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 idx,
const unsigned char *data,
size_t len)
{
size_t i;
ares_status_t status;
/* Each line is 16 bytes */
for (i = 0; i < len; i += 16) {
size_t j;
/* 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;
}
@ -908,11 +907,11 @@ ares_status_t ares__buf_hexdump(ares__buf_t *buf, const unsigned char *data,
return status;
}
for (j = i; j < i + 16; j++) {
if (j >= len) {
for (i = 0; i < 16; i++) {
if (i >= len) {
status = ares__buf_append_str(buf, " ");
} else {
status = ares__buf_append_num_hex(buf, data[j], 2);
status = ares__buf_append_num_hex(buf, data[i], 2);
}
if (status != ARES_SUCCESS) {
return status;
@ -930,18 +929,31 @@ ares_status_t ares__buf_hexdump(ares__buf_t *buf, const unsigned char *data,
return status;
}
for (j = i; j < i + 16; j++) {
if (j >= len) {
for (i = 0; i < 16; i++) {
if (i >= len) {
break;
}
status =
ares__buf_append_byte(buf, ares__isprint(data[j]) ? data[j] : '.');
ares__buf_append_byte(buf, ares__isprint(data[i]) ? data[i] : '.');
if (status != ARES_SUCCESS) {
return status;
}
}
ares__buf_append_byte(buf, '\n');
return 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;

@ -192,7 +192,12 @@ static ares_status_t ares_dns_write_rr_str(ares__buf_t *buf,
ares_status_t status;
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;
}

@ -506,7 +506,7 @@ static void ares__servers_remove_stale(ares_channel_t *channel,
while (snode != NULL) {
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)) {
/* This will clean up all server state via the destruction callback and
* move any queries to new servers */

Loading…
Cancel
Save