diff --git a/include/ares.h b/include/ares.h index d6792af9..d5d6ba89 100644 --- a/include/ares.h +++ b/include/ares.h @@ -308,7 +308,7 @@ struct ares_options { char *hosts_path; int udp_max_queries; int maxtimeout; /* in milliseconds */ - unsigned int qcache_max_ttl; /* Maximum TTL for query cache, 0=disabled */ + unsigned int qcache_max_ttl; /* Maximum TTL for query cache, 0=disabled */ }; struct hostent; diff --git a/src/lib/ares__buf.c b/src/lib/ares__buf.c index 0237a5a7..a885db3b 100644 --- a/src/lib/ares__buf.c +++ b/src/lib/ares__buf.c @@ -862,7 +862,7 @@ ares_status_t ares__buf_append_num_dec(ares__buf_t *buf, size_t num, size_t len) size_t digit = (num % mod); ares_status_t status; - mod /= 10; + mod /= 10; /* Silence coverity. Shouldn't be possible since we calculate it above */ if (mod == 0) { diff --git a/src/lib/ares__buf.h b/src/lib/ares__buf.h index b73d8ee2..a36257ef 100644 --- a/src/lib/ares__buf.h +++ b/src/lib/ares__buf.h @@ -96,7 +96,7 @@ ares_status_t ares__buf_append_byte(ares__buf_t *buf, unsigned char byte); * \param[in] str String to append to buffer object. * \return ARES_SUCCESS or one of the c-ares error codes */ -ares_status_t ares__buf_append_str(ares__buf_t *buf, const char *str); +ares_status_t ares__buf_append_str(ares__buf_t *buf, const char *str); /*! Append a 16bit Big Endian number to the buffer. * diff --git a/src/lib/ares__hosts_file.c b/src/lib/ares__hosts_file.c index 46b30b43..85144428 100644 --- a/src/lib/ares__hosts_file.c +++ b/src/lib/ares__hosts_file.c @@ -319,10 +319,9 @@ typedef enum { ARES_MATCH_HOST = 2 } ares_hosts_file_match_t; -static ares_status_t ares__hosts_file_merge_entry(ares_hosts_file_t *hf, - ares_hosts_entry_t *existing, - ares_hosts_entry_t *entry, - ares_hosts_file_match_t matchtype) +static ares_status_t ares__hosts_file_merge_entry( + ares_hosts_file_t *hf, ares_hosts_entry_t *existing, + ares_hosts_entry_t *entry, ares_hosts_file_match_t matchtype) { ares__llist_node_t *node; @@ -357,8 +356,6 @@ static ares_status_t ares__hosts_file_merge_entry(ares_hosts_file_t *hf, return ARES_SUCCESS; } - - static ares_hosts_file_match_t ares__hosts_file_match(const ares_hosts_file_t *hf, ares_hosts_entry_t *entry, ares_hosts_entry_t **match) @@ -392,7 +389,7 @@ static ares_status_t ares__hosts_file_add(ares_hosts_file_t *hosts, ares_hosts_entry_t *entry) { ares_hosts_entry_t *match = NULL; - ares_status_t status = ARES_SUCCESS; + ares_status_t status = ARES_SUCCESS; ares__llist_node_t *node; ares_hosts_file_match_t matchtype; size_t num_hostnames; @@ -432,8 +429,9 @@ static ares_status_t ares__hosts_file_add(ares_hosts_file_t *hosts, node = ares__llist_node_prev(node)) { const char *val = ares__llist_node_val(node); - if (num_hostnames == 0) + if (num_hostnames == 0) { break; + } num_hostnames--; @@ -753,7 +751,7 @@ static ares_status_t ares__hosts_path(const ares_channel_t *channel, char PATH_HOSTS[MAX_PATH] = ""; char tmp[MAX_PATH]; HKEY hkeyHosts; - DWORD dwLength = sizeof(tmp); + DWORD dwLength = sizeof(tmp); if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts) != ERROR_SUCCESS) { return ARES_ENOTFOUND; @@ -939,8 +937,9 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry, /* Cap at 100, some people use https://github.com/StevenBlack/hosts and we * don't need 200k+ aliases */ - if (naliases > 100) + if (naliases > 100) { naliases = 100; + } (*hostent)->h_aliases = ares_malloc_zero((naliases + 1) * sizeof(*(*hostent)->h_aliases)); @@ -962,8 +961,9 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry, idx++; /* Break out if artificially capped */ - if (idx == naliases) + if (idx == naliases) { break; + } node = ares__llist_node_next(node); } @@ -994,11 +994,12 @@ static ares_status_t while (node != NULL) { const char *host = ares__llist_node_val(node); - /* Cap at 100 entries. , some people use https://github.com/StevenBlack/hosts - * and we don't need 200k+ aliases */ + /* Cap at 100 entries. , some people use + * https://github.com/StevenBlack/hosts and we don't need 200k+ aliases */ cnt++; - if (cnt > 100) + if (cnt > 100) { break; + } cname = ares__append_addrinfo_cname(&cnames); if (cname == NULL) { diff --git a/src/lib/ares__htable.c b/src/lib/ares__htable.c index 7390c644..4d4f3a7a 100644 --- a/src/lib/ares__htable.c +++ b/src/lib/ares__htable.c @@ -159,8 +159,8 @@ static ares__llist_node_t *ares__htable_find(const ares__htable_t *htable, static ares_bool_t ares__htable_expand(ares__htable_t *htable) { - ares__llist_t **buckets = NULL; - unsigned int old_size = htable->size; + ares__llist_t **buckets = NULL; + unsigned int old_size = htable->size; size_t i; ares__llist_t **prealloc_llist = NULL; size_t prealloc_llist_len = 0; @@ -185,13 +185,13 @@ static ares_bool_t ares__htable_expand(ares__htable_t *htable) * that were recorded */ prealloc_llist_len = htable->num_collisions; if (prealloc_llist_len) { - prealloc_llist = ares_malloc_zero(sizeof(*prealloc_llist) * - prealloc_llist_len); + prealloc_llist = + ares_malloc_zero(sizeof(*prealloc_llist) * prealloc_llist_len); if (prealloc_llist == NULL) { goto done; } } - for (i=0; ibucket_free); if (prealloc_llist[i] == NULL) { goto done; @@ -204,8 +204,9 @@ static ares_bool_t ares__htable_expand(ares__htable_t *htable) ares__llist_node_t *node; /* Nothing in this bucket */ - if (htable->buckets[i] == NULL) + if (htable->buckets[i] == NULL) { continue; + } /* Fast path optimization (most likely case), there is likely only a single * entry in both the source and destination, check for this to confirm and @@ -242,7 +243,7 @@ static ares_bool_t ares__htable_expand(ares__htable_t *htable) if (prealloc_llist == NULL || prealloc_llist_len == 0) { goto done; } - buckets[idx] = prealloc_llist[prealloc_llist_len-1]; + buckets[idx] = prealloc_llist[prealloc_llist_len - 1]; prealloc_llist_len--; } else { /* Collision occurred since the bucket wasn't empty */ diff --git a/src/lib/ares__llist.c b/src/lib/ares__llist.c index fd51ff9f..d175da2b 100644 --- a/src/lib/ares__llist.c +++ b/src/lib/ares__llist.c @@ -76,8 +76,9 @@ static void ares__llist_attach_at(ares__llist_t *list, ares__llist_node_t *at, ares__llist_node_t *node) { - if (list == NULL || node == NULL) + if (list == NULL || node == NULL) { return; + } node->parent = list; @@ -248,8 +249,9 @@ static void ares__llist_node_detach(ares__llist_node_t *node) { ares__llist_t *list; - if (node == NULL) + if (node == NULL) { return; + } list = node->parent; @@ -275,13 +277,13 @@ static void ares__llist_node_detach(ares__llist_node_t *node) void *ares__llist_node_claim(ares__llist_node_t *node) { - void *val; + void *val; if (node == NULL) { return NULL; } - val = node->data; + val = node->data; ares__llist_node_detach(node); ares_free(node); @@ -336,20 +338,22 @@ void ares__llist_destroy(ares__llist_t *list) } void ares__llist_node_move_parent_last(ares__llist_node_t *node, - ares__llist_t *new_parent) + ares__llist_t *new_parent) { - if (node == NULL || new_parent == NULL) + if (node == NULL || new_parent == NULL) { return; + } ares__llist_node_detach(node); ares__llist_attach_at(new_parent, ARES__LLIST_INSERT_TAIL, NULL, node); } void ares__llist_node_move_parent_first(ares__llist_node_t *node, - ares__llist_t *new_parent) + ares__llist_t *new_parent) { - if (node == NULL || new_parent == NULL) + if (node == NULL || new_parent == NULL) { return; + } ares__llist_node_detach(node); ares__llist_attach_at(new_parent, ARES__LLIST_INSERT_HEAD, NULL, node); diff --git a/src/lib/ares__llist.h b/src/lib/ares__llist.h index 0da7c7b5..bd18bb9e 100644 --- a/src/lib/ares__llist.h +++ b/src/lib/ares__llist.h @@ -205,7 +205,7 @@ void ares__llist_destroy(ares__llist_t *list); * \param[in] parent new list */ void ares__llist_node_move_parent_last(ares__llist_node_t *node, - ares__llist_t *new_parent); + ares__llist_t *new_parent); /*! Detach node from the current list and re-attach it to the new list as the * first entry. @@ -214,7 +214,7 @@ void ares__llist_node_move_parent_last(ares__llist_node_t *node, * \param[in] parent new list */ void ares__llist_node_move_parent_first(ares__llist_node_t *node, - ares__llist_t *new_parent); + ares__llist_t *new_parent); /*! @} */ #endif /* __ARES__LLIST_H */ diff --git a/src/lib/ares__socket.c b/src/lib/ares__socket.c index 1ecd44ec..67cd9376 100644 --- a/src/lib/ares__socket.c +++ b/src/lib/ares__socket.c @@ -402,8 +402,9 @@ int ares__connect_socket(ares_channel_t *channel, ares_socket_t sockfd, void ares__close_socket(ares_channel_t *channel, ares_socket_t s) { - if (s == ARES_SOCKET_BAD) + if (s == ARES_SOCKET_BAD) { return; + } if (channel->sock_funcs && channel->sock_funcs->aclose) { channel->sock_funcs->aclose(s, channel->sock_func_cb_data); diff --git a/src/lib/ares_dns_private.h b/src/lib/ares_dns_private.h index c8f4720c..91635e74 100644 --- a/src/lib/ares_dns_private.h +++ b/src/lib/ares_dns_private.h @@ -46,8 +46,8 @@ ares_status_t ares_dns_rr_set_opt_own(ares_dns_rr_t *dns_rr, ares_status_t ares_dns_record_rr_prealloc(ares_dns_record_t *dnsrec, ares_dns_section_t sect, size_t cnt); ares_bool_t ares_dns_has_opt_rr(const ares_dns_record_t *rec); -void ares_dns_record_write_ttl_decrement(ares_dns_record_t *dnsrec, - unsigned int ttl_decrement); +void ares_dns_record_write_ttl_decrement(ares_dns_record_t *dnsrec, + unsigned int ttl_decrement); struct ares_dns_qd { char *name; @@ -204,13 +204,13 @@ struct ares_dns_rr { /*! DNS data structure */ struct ares_dns_record { - unsigned short id; /*!< DNS query id */ - unsigned short flags; /*!< One or more ares_dns_flags_t */ - ares_dns_opcode_t opcode; /*!< DNS Opcode */ - ares_dns_rcode_t rcode; /*!< DNS RCODE */ - unsigned short raw_rcode; /*!< Raw rcode, used to ultimately form real - * rcode after reading OPT record if it - * exists */ + unsigned short id; /*!< DNS query id */ + unsigned short flags; /*!< One or more ares_dns_flags_t */ + ares_dns_opcode_t opcode; /*!< DNS Opcode */ + ares_dns_rcode_t rcode; /*!< DNS RCODE */ + unsigned short raw_rcode; /*!< Raw rcode, used to ultimately form real + * rcode after reading OPT record if it + * exists */ unsigned int ttl_decrement; /*!< Special case to apply to writing out * this record, where it will decrement * the ttl of any resource records by diff --git a/src/lib/ares_dns_write.c b/src/lib/ares_dns_write.c index d7e92e7d..2e99c5ba 100644 --- a/src/lib/ares_dns_write.c +++ b/src/lib/ares_dns_write.c @@ -881,7 +881,7 @@ static ares_status_t ares_dns_write_rr(ares_dns_record_t *dnsrec, } /* TTL */ - ttl = ares_dns_rr_get_ttl(rr); + ttl = ares_dns_rr_get_ttl(rr); if (rr->parent->ttl_decrement > ttl) { ttl = 0; } else { @@ -1044,11 +1044,11 @@ done: return status; } - void ares_dns_record_write_ttl_decrement(ares_dns_record_t *dnsrec, - unsigned int ttl_decrement) + unsigned int ttl_decrement) { - if (dnsrec == NULL) + if (dnsrec == NULL) { return; + } dnsrec->ttl_decrement = ttl_decrement; } diff --git a/src/lib/ares_private.h b/src/lib/ares_private.h index 14931ca5..5b9c6698 100644 --- a/src/lib/ares_private.h +++ b/src/lib/ares_private.h @@ -477,10 +477,9 @@ ares_status_t ares__sconfig_append(ares__llist_t **sconfig, unsigned short tcp_port); ares_status_t ares__sconfig_append_fromstr(ares__llist_t **sconfig, const char *str); -ares_status_t - ares_in_addr_to_server_config_llist(const struct in_addr *servers, - size_t nservers, - ares__llist_t **llist); +ares_status_t ares_in_addr_to_server_config_llist(const struct in_addr *servers, + size_t nservers, + ares__llist_t **llist); struct ares_hosts_entry; typedef struct ares_hosts_entry ares_hosts_entry_t; @@ -559,30 +558,29 @@ ares_status_t ares__dns_name_write(ares__buf_t *buf, ares__llist_t **list, (x && x->lookups && ares__slist_len(x->servers) > 0 && x->ndots > 0 && \ x->timeout > 0 && x->tries > 0) -size_t ares__round_up_pow2(size_t n); -size_t ares__log2(size_t n); -size_t ares__pow(size_t x, size_t y); -size_t ares__count_digits(size_t n); -size_t ares__count_hexdigits(size_t n); -void ares__qcache_destroy(ares__qcache_t *cache); +size_t ares__round_up_pow2(size_t n); +size_t ares__log2(size_t n); +size_t ares__pow(size_t x, size_t y); +size_t ares__count_digits(size_t n); +size_t ares__count_hexdigits(size_t n); +void ares__qcache_destroy(ares__qcache_t *cache); ares_status_t ares__qcache_create(ares_rand_state *rand_state, unsigned int max_ttl, ares__qcache_t **cache_out); -void ares__qcache_flush(ares__qcache_t *cache); -ares_status_t ares_qcache_insert(ares_channel_t *channel, - struct timeval *now, +void ares__qcache_flush(ares__qcache_t *cache); +ares_status_t ares_qcache_insert(ares_channel_t *channel, struct timeval *now, struct query *query, ares_dns_record_t *dnsrec); ares_status_t ares_qcache_fetch(ares_channel_t *channel, struct timeval *now, const unsigned char *qbuf, size_t qlen, unsigned char **abuf, size_t *alen); -# ifdef _MSC_VER +#ifdef _MSC_VER typedef __int64 ares_int64_t; typedef unsigned __int64 ares_uint64_t; -# else +#else typedef long long ares_int64_t; typedef unsigned long long ares_uint64_t; -# endif +#endif #endif /* __ARES_PRIVATE_H */ diff --git a/src/lib/ares_process.c b/src/lib/ares_process.c index 0c34d7f1..f80ef8af 100644 --- a/src/lib/ares_process.c +++ b/src/lib/ares_process.c @@ -116,8 +116,9 @@ ares_bool_t ares__timedout(const struct timeval *now, } /* if the full seconds were identical, check the sub second parts */ - return ((ares_int64_t)now->tv_usec - (ares_int64_t)check->tv_usec) >= 0 ? - ARES_TRUE : ARES_FALSE; + return ((ares_int64_t)now->tv_usec - (ares_int64_t)check->tv_usec) >= 0 + ? ARES_TRUE + : ARES_FALSE; } /* add the specific number of milliseconds to the time in the first argument */ @@ -776,8 +777,9 @@ static struct server_state *ares__random_server(ares_channel_t *channel) size_t num_servers = ares__slist_len(channel->servers); /* Silence coverity, not possible */ - if (num_servers == 0) + if (num_servers == 0) { return NULL; + } ares__rand_bytes(channel->rand_state, &c, 1); @@ -811,13 +813,14 @@ static ares_status_t ares__append_tcpbuf(struct server_state *server, static size_t ares__calc_query_timeout(const struct query *query) { - const ares_channel_t *channel = query->channel; - size_t timeplus = channel->timeout; + const ares_channel_t *channel = query->channel; + size_t timeplus = channel->timeout; size_t rounds; size_t num_servers = ares__slist_len(channel->servers); - if (num_servers == 0) + if (num_servers == 0) { return 0; + } /* For each trip through the entire server list, we want to double the * retry from the last retry */ diff --git a/src/lib/ares_qcache.c b/src/lib/ares_qcache.c index e81ef78c..1d06c33e 100644 --- a/src/lib/ares_qcache.c +++ b/src/lib/ares_qcache.c @@ -287,7 +287,7 @@ static unsigned int ares__qcache_soa_minimum(ares_dns_record_t *dnsrec) } static char *ares__qcache_calc_key_frombuf(const unsigned char *qbuf, - size_t qlen) + size_t qlen) { ares_status_t status; ares_dns_record_t *dnsrec = NULL; @@ -306,11 +306,10 @@ done: } /* On success, takes ownership of dnsrec */ -static ares_status_t ares__qcache_insert(ares__qcache_t *qcache, - ares_dns_record_t *dnsrec, - const unsigned char *qbuf, - size_t qlen, - struct timeval *now) +static ares_status_t ares__qcache_insert(ares__qcache_t *qcache, + ares_dns_record_t *dnsrec, + const unsigned char *qbuf, size_t qlen, + struct timeval *now) { ares__qcache_entry_t *entry; unsigned int ttl; @@ -352,7 +351,7 @@ static ares_status_t ares__qcache_insert(ares__qcache_t *qcache, goto fail; } - entry->dnsrec = dnsrec; + entry->dnsrec = dnsrec; entry->expire_ts = now->tv_sec + ttl; entry->insert_ts = now->tv_sec; @@ -360,7 +359,7 @@ static ares_status_t ares__qcache_insert(ares__qcache_t *qcache, * request had, so we have to re-parse the request in order to generate the * key for caching, but we'll only do this once we know for sure we really * want to cache it */ - entry->key = ares__qcache_calc_key_frombuf(qbuf, qlen); + entry->key = ares__qcache_calc_key_frombuf(qbuf, qlen); if (entry->key == NULL) { goto fail; } @@ -422,8 +421,7 @@ done: } ares_status_t ares_qcache_insert(ares_channel_t *channel, struct timeval *now, - struct query *query, - ares_dns_record_t *dnsrec) + struct query *query, ares_dns_record_t *dnsrec) { return ares__qcache_insert(channel->qcache, dnsrec, query->qbuf, query->qlen, now); diff --git a/src/lib/ares_rand.c b/src/lib/ares_rand.c index 15cfd71a..86313b2d 100644 --- a/src/lib/ares_rand.c +++ b/src/lib/ares_rand.c @@ -53,8 +53,6 @@ typedef struct ares_rand_rc4 { size_t j; } ares_rand_rc4; - - static unsigned int ares_u32_from_ptr(void *addr) { if (sizeof(void *) == 8) { diff --git a/src/lib/ares_send.c b/src/lib/ares_send.c index 9f00a58a..7c450069 100644 --- a/src/lib/ares_send.c +++ b/src/lib/ares_send.c @@ -56,7 +56,7 @@ ares_status_t ares_send_ex(ares_channel_t *channel, const unsigned char *qbuf, size_t packetsz; struct timeval now = ares__tvnow(); ares_status_t status; - unsigned short id = generate_unique_qid(channel); + unsigned short id = generate_unique_qid(channel); unsigned char *abuf = NULL; size_t alen = 0; diff --git a/src/lib/ares_update_servers.c b/src/lib/ares_update_servers.c index 9075b736..79bdb68e 100644 --- a/src/lib/ares_update_servers.c +++ b/src/lib/ares_update_servers.c @@ -643,8 +643,7 @@ fail: } static ares_status_t ares_addr_port_node_to_server_config_llist( - const struct ares_addr_port_node *servers, - ares__llist_t **llist) + const struct ares_addr_port_node *servers, ares__llist_t **llist) { const struct ares_addr_port_node *node; ares__llist_t *s; @@ -695,10 +694,9 @@ fail: return ARES_ENOMEM; } -ares_status_t - ares_in_addr_to_server_config_llist(const struct in_addr *servers, - size_t nservers, - ares__llist_t **llist) +ares_status_t ares_in_addr_to_server_config_llist(const struct in_addr *servers, + size_t nservers, + ares__llist_t **llist) { size_t i; ares__llist_t *s; diff --git a/src/lib/config-win32.h b/src/lib/config-win32.h index e70d8682..da7b67d6 100644 --- a/src/lib/config-win32.h +++ b/src/lib/config-win32.h @@ -98,7 +98,7 @@ /* If we are building with OpenWatcom, we need to specify that we have * . */ #if defined(__WATCOMC__) -#define HAVE_STDINT_H +# define HAVE_STDINT_H #endif /* ---------------------------------------------------------------- */