Sonarcloud: fix minor codesmells, mostly related to marking more parameters and variables as const

pull/774/head
Brad House 6 months ago
parent a6c8fe685d
commit ac7ab82633
  1. 10
      src/lib/ares__htable_vpvp.c
  2. 9
      src/lib/ares__htable_vpvp.h
  3. 15
      src/lib/ares_event_configchg.c
  4. 30
      src/lib/ares_process.c

@ -146,8 +146,8 @@ fail:
return ARES_FALSE;
}
ares_bool_t ares__htable_vpvp_get(const ares__htable_vpvp_t *htable, void *key,
void **val)
ares_bool_t ares__htable_vpvp_get(const ares__htable_vpvp_t *htable,
const void *key, void **val)
{
ares__htable_vpvp_bucket_t *bucket = NULL;
@ -170,14 +170,16 @@ ares_bool_t ares__htable_vpvp_get(const ares__htable_vpvp_t *htable, void *key,
return ARES_TRUE;
}
void *ares__htable_vpvp_get_direct(const ares__htable_vpvp_t *htable, void *key)
void *ares__htable_vpvp_get_direct(const ares__htable_vpvp_t *htable,
const void *key)
{
void *val = NULL;
ares__htable_vpvp_get(htable, key, &val);
return val;
}
ares_bool_t ares__htable_vpvp_remove(ares__htable_vpvp_t *htable, void *key)
ares_bool_t ares__htable_vpvp_remove(ares__htable_vpvp_t *htable,
const void *key)
{
if (htable == NULL) {
return ARES_FALSE;

@ -93,8 +93,8 @@ ares_bool_t ares__htable_vpvp_insert(ares__htable_vpvp_t *htable, void *key,
* \param[out] val Optional. Pointer to store value.
* \return ARES_TRUE on success, ARES_FALSE on failure
*/
ares_bool_t ares__htable_vpvp_get(const ares__htable_vpvp_t *htable, void *key,
void **val);
ares_bool_t ares__htable_vpvp_get(const ares__htable_vpvp_t *htable,
const void *key, void **val);
/*! Retrieve value from hashtable directly as return value. Caveat to this
* function over ares__htable_vpvp_get() is that if a NULL value is stored
@ -105,7 +105,7 @@ ares_bool_t ares__htable_vpvp_get(const ares__htable_vpvp_t *htable, void *key,
* \return value associated with key in hashtable or NULL
*/
void *ares__htable_vpvp_get_direct(const ares__htable_vpvp_t *htable,
void *key);
const void *key);
/*! Remove a value from the hashtable by key
*
@ -113,7 +113,8 @@ void *ares__htable_vpvp_get_direct(const ares__htable_vpvp_t *htable,
* \param[in] key key to use to search
* \return ARES_TRUE if found, ARES_FALSE if not
*/
ares_bool_t ares__htable_vpvp_remove(ares__htable_vpvp_t *htable, void *key);
ares_bool_t ares__htable_vpvp_remove(ares__htable_vpvp_t *htable,
const void *key);
/*! Retrieve the number of keys stored in the hash table
*

@ -28,11 +28,6 @@
#include "ares_private.h"
#include "ares_event.h"
static void ares_event_configchg_reload(ares_event_thread_t *e)
{
ares_reinit(e->channel);
}
#ifdef __ANDROID__
ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg,
@ -86,7 +81,7 @@ static void ares_event_configchg_free(void *data)
static void ares_event_configchg_cb(ares_event_thread_t *e, ares_socket_t fd,
void *data, ares_event_flags_t flags)
{
ares_event_configchg_t *configchg = data;
const ares_event_configchg_t *configchg = data;
/* Some systems cannot read integer variables if they are not
* properly aligned. On other systems, incorrect alignment may
@ -130,7 +125,7 @@ static void ares_event_configchg_cb(ares_event_thread_t *e, ares_socket_t fd,
/* Only process after all events are read. No need to process more often as
* we don't want to reload the config back to back */
if (triggered) {
ares_event_configchg_reload(e);
ares_reinit(e->channel);
}
}
@ -214,7 +209,7 @@ static void ares_event_configchg_cb(PVOID CallerContext,
ares_event_configchg_t *configchg = CallerContext;
(void)Row;
(void)NotificationType;
ares_event_configchg_reload(configchg->e);
ares_reinit(configchg->e->channel);
}
# endif
@ -324,7 +319,7 @@ static void ares_event_configchg_cb(ares_event_thread_t *e, ares_socket_t fd,
/* Only process after all events are read. No need to process more often as
* we don't want to reload the config back to back */
if (triggered) {
ares_event_configchg_reload(e);
ares_reinit(e->channel);
}
}
@ -474,7 +469,7 @@ static void *ares_event_configchg_thread(void *arg)
status = config_change_check(c->filestat, c->resolvconf_path);
if (status == ARES_SUCCESS) {
ares_event_configchg_reload(c->e);
ares_reinit(c->e->channel);
}
}

@ -55,12 +55,14 @@ static ares_bool_t try_again(int errnum);
static void write_tcp_data(ares_channel_t *channel, fd_set *write_fds,
ares_socket_t write_fd);
static void read_packets(ares_channel_t *channel, fd_set *read_fds,
ares_socket_t read_fd, ares_timeval_t *now);
static void process_timeouts(ares_channel_t *channel, ares_timeval_t *now);
ares_socket_t read_fd,
const ares_timeval_t *now);
static void process_timeouts(ares_channel_t *channel,
const ares_timeval_t *now);
static ares_status_t process_answer(ares_channel_t *channel,
const unsigned char *abuf, size_t alen,
struct server_connection *conn,
ares_bool_t tcp, ares_timeval_t *now);
ares_bool_t tcp, const ares_timeval_t *now);
static void handle_conn_error(struct server_connection *conn,
ares_bool_t critical_failure);
@ -69,7 +71,8 @@ static ares_bool_t same_questions(const ares_dns_record_t *qrec,
static ares_bool_t same_address(const struct sockaddr *sa,
const struct ares_addr *aa);
static void end_query(ares_channel_t *channel, struct query *query,
ares_status_t status, const ares_dns_record_t *dnsrec);
ares_status_t status,
const ares_dns_record_t *dnsrec);
/* Invoke the server state callback after a success or failure */
static void invoke_server_state_cb(const struct server_state *server,
@ -324,7 +327,8 @@ static void write_tcp_data(ares_channel_t *channel, fd_set *write_fds,
* a packet if we finish reading one.
*/
static void read_tcp_data(ares_channel_t *channel,
struct server_connection *conn, ares_timeval_t *now)
struct server_connection *conn,
const ares_timeval_t *now)
{
ares_ssize_t count;
struct server_state *server = conn->server;
@ -463,7 +467,7 @@ fail:
/* If any UDP sockets select true for reading, process them. */
static void read_udp_packets_fd(ares_channel_t *channel,
struct server_connection *conn,
ares_timeval_t *now)
const ares_timeval_t *now)
{
ares_ssize_t read_len;
unsigned char buf[MAXENDSSZ + 1];
@ -527,7 +531,7 @@ static void read_udp_packets_fd(ares_channel_t *channel,
}
static void read_packets(ares_channel_t *channel, fd_set *read_fds,
ares_socket_t read_fd, ares_timeval_t *now)
ares_socket_t read_fd, const ares_timeval_t *now)
{
size_t i;
ares_socket_t *socketlist = NULL;
@ -594,7 +598,7 @@ static void read_packets(ares_channel_t *channel, fd_set *read_fds,
}
/* If any queries have timed out, note the timeout and move them on. */
static void process_timeouts(ares_channel_t *channel, ares_timeval_t *now)
static void process_timeouts(ares_channel_t *channel, const ares_timeval_t *now)
{
ares__slist_node_t *node =
ares__slist_node_first(channel->queries_by_timeout);
@ -667,7 +671,7 @@ done:
static ares_status_t process_answer(ares_channel_t *channel,
const unsigned char *abuf, size_t alen,
struct server_connection *conn,
ares_bool_t tcp, ares_timeval_t *now)
ares_bool_t tcp, const ares_timeval_t *now)
{
struct query *query;
/* Cache these as once ares__send_query() gets called, it may end up
@ -883,9 +887,11 @@ static struct server_state *ares__random_server(ares_channel_t *channel)
*/
static struct server_state *ares__failover_server(ares_channel_t *channel)
{
struct server_state *first_server = ares__slist_first_val(channel->servers);
struct server_state *last_server = ares__slist_last_val(channel->servers);
unsigned short r;
struct server_state *first_server =
ares__slist_first_val(channel->servers);
const struct server_state *last_server =
ares__slist_last_val(channel->servers);
unsigned short r;
/* Defensive code against no servers being available on the channel. */
if (first_server == NULL) {

Loading…
Cancel
Save