Commit 495fb00b authored by Simon Giesecke's avatar Simon Giesecke

Problem: pointee types are unnecessarily non-const

Solution: add const where possible
parent db8f4fba
......@@ -72,9 +72,7 @@ template <> class dbuffer_t<msg_t>
void write (const msg_t &value_)
{
msg_t &xvalue = const_cast<msg_t &> (value_);
zmq_assert (xvalue.check ());
zmq_assert (value_.check ());
*_back = value_;
zmq_assert (_back->check ());
......
......@@ -189,8 +189,8 @@ void zmq::epoll_t::loop ()
}
for (int i = 0; i < n; i++) {
poll_entry_t *pe =
(static_cast<poll_entry_t *> (ev_buf[i].data.ptr));
const poll_entry_t *const pe =
static_cast<const poll_entry_t *> (ev_buf[i].data.ptr);
if (pe->fd == retired_fd)
continue;
......
......@@ -859,7 +859,7 @@ int zmq::create_ipc_wildcard_address (std::string &path_, std::string &file_)
// the socket directory there.
const char **tmp_env = tmp_env_vars;
while (tmp_path.empty () && *tmp_env != 0) {
char *tmpdir = getenv (*tmp_env);
const char *const tmpdir = getenv (*tmp_env);
struct stat statbuf;
// Confirm it is actually a directory before trying to use
......
......@@ -540,7 +540,7 @@ int zmq::ip_resolver_t::resolve_nic_name (ip_addr_t *ip_addr_, const char *nic_)
// Find the corresponding network interface.
bool found = false;
for (ifaddrs *ifp = ifa; ifp != NULL; ifp = ifp->ifa_next) {
for (const ifaddrs *ifp = ifa; ifp != NULL; ifp = ifp->ifa_next) {
if (ifp->ifa_addr == NULL)
continue;
......
......@@ -248,8 +248,8 @@ bool zmq::ipc_listener_t::filter (fd_t sock_)
!= options.ipc_pid_accept_filters.end ())
return true;
struct passwd *pw;
struct group *gr;
const struct passwd *pw;
const struct group *gr;
if (!(pw = getpwuid (cred.uid)))
return false;
......
......@@ -218,7 +218,7 @@ int zmq::radio_session_t::push_msg (msg_t *msg_)
const size_t data_size = msg_->size ();
int group_length;
char *group;
const char *group;
msg_t join_leave_msg;
int rc;
......
......@@ -487,7 +487,8 @@ bool zmq::router_t::identify_peer (pipe_t *pipe_, bool locally_initiated_)
// Try to remove an existing routing id entry to allow the new
// connection to take the routing id.
out_pipe_t *existing_outpipe = lookup_out_pipe (routing_id);
const out_pipe_t *const existing_outpipe =
lookup_out_pipe (routing_id);
if (existing_outpipe) {
if (!_handover)
......
......@@ -981,8 +981,9 @@ int zmq::socket_base_t::connect (const char *endpoint_uri_)
LIBZMQ_DELETE (paddr);
return -1;
}
sockaddr_tipc *saddr =
(sockaddr_tipc *) paddr->resolved.tipc_addr->addr ();
const sockaddr_tipc *const saddr =
reinterpret_cast<const sockaddr_tipc *> (
paddr->resolved.tipc_addr->addr ());
// Cannot connect to random Port Identity
if (saddr->addrtype == TIPC_ADDR_ID
&& paddr->resolved.tipc_addr->is_random ()) {
......
......@@ -93,7 +93,8 @@ int zmq::tipc_listener_t::set_local_address (const char *addr_)
return -1;
// Cannot bind non-random Port Identity
struct sockaddr_tipc *a = (sockaddr_tipc *) _address.addr ();
const sockaddr_tipc *const a =
reinterpret_cast<const sockaddr_tipc *> (_address.addr ());
if (!_address.is_random () && a->addrtype == TIPC_ADDR_ID) {
errno = EINVAL;
return -1;
......
......@@ -236,11 +236,11 @@ bool zmq::trie_t::rm (unsigned char *prefix_, size_t size_)
return ret;
}
bool zmq::trie_t::check (const unsigned char *data_, size_t size_)
bool zmq::trie_t::check (const unsigned char *data_, size_t size_) const
{
// This function is on critical path. It deliberately doesn't use
// recursion to get a bit better performance.
trie_t *current = this;
const trie_t *current = this;
while (true) {
// We've found a corresponding subscription!
if (current->_refcnt)
......
......@@ -52,7 +52,7 @@ class trie_t
bool rm (unsigned char *prefix_, size_t size_);
// Check whether particular key is in the trie.
bool check (const unsigned char *data_, size_t size_);
bool check (const unsigned char *data_, size_t size_) const;
// Apply the function supplied to each subscription in the trie.
void apply (void (*func_) (unsigned char *data_, size_t size_, void *arg_),
......
......@@ -1135,8 +1135,8 @@ void *zmq_poller_new (void)
int zmq_poller_destroy (void **poller_p_)
{
if (poller_p_) {
zmq::socket_poller_t *const poller =
static_cast<zmq::socket_poller_t *> (*poller_p_);
const zmq::socket_poller_t *const poller =
static_cast<const zmq::socket_poller_t *> (*poller_p_);
if (poller && poller->check_tag ()) {
delete poller;
*poller_p_ = NULL;
......@@ -1227,7 +1227,8 @@ int zmq_poller_modify (void *poller_, void *s_, short events_)
|| -1 == check_events (events_))
return -1;
zmq::socket_base_t *socket = static_cast<zmq::socket_base_t *> (s_);
const zmq::socket_base_t *const socket =
static_cast<const zmq::socket_base_t *> (s_);
return (static_cast<zmq::socket_poller_t *> (poller_))
->modify (socket, events_);
......
......@@ -545,7 +545,8 @@ int zmq::zmtp_engine_t::process_command_message (msg_t *msg_)
if (unlikely (msg_->size () < cmd_name_size + sizeof (cmd_name_size)))
return -1;
uint8_t *cmd_name = (static_cast<uint8_t *> (msg_->data ())) + 1;
const uint8_t *const cmd_name =
static_cast<const uint8_t *> (msg_->data ()) + 1;
if (cmd_name_size == ping_name_size
&& memcmp (cmd_name, "PING", cmd_name_size) == 0)
msg_->set_flags (zmq::msg_t::ping);
......
......@@ -123,10 +123,10 @@ void test_app_meta_reqrep ()
TEST_ASSERT_EQUAL_STRING ("hello", zmq_msg_gets (&msg, "X-hello"));
TEST_ASSERT_EQUAL_STRING ("primary", zmq_msg_gets (&msg, "X-connection"));
char *bindata = const_cast<char *> (zmq_msg_gets (&msg, "X-bin"));
const char *const bindata = zmq_msg_gets (&msg, "X-bin");
TEST_ASSERT_NOT_NULL (bindata);
uint8_t rawdata[4];
void *ret = zmq_z85_decode (rawdata, bindata);
const uint8_t *const ret = zmq_z85_decode (rawdata, bindata);
TEST_ASSERT_NOT_NULL (ret);
TEST_ASSERT_EQUAL_UINT8 (0, rawdata[0]);
TEST_ASSERT_EQUAL_UINT8 (1, rawdata[1]);
......
......@@ -94,11 +94,12 @@ void test__zmq_z85_encode__zmq_z85_decode__roundtrip (
const uint8_t (&test_data_)[SIZE])
{
char test_data_z85[SIZE * 5 / 4 + 1];
char *res1 = zmq_z85_encode (test_data_z85, test_data_, SIZE);
const char *const res1 = zmq_z85_encode (test_data_z85, test_data_, SIZE);
TEST_ASSERT_NOT_NULL (res1);
uint8_t test_data_decoded[SIZE];
uint8_t *res2 = zmq_z85_decode (test_data_decoded, test_data_z85);
const uint8_t *const res2 =
zmq_z85_decode (test_data_decoded, test_data_z85);
TEST_ASSERT_NOT_NULL (res2);
TEST_ASSERT_EQUAL_UINT8_ARRAY (test_data_, test_data_decoded, SIZE);
......@@ -111,11 +112,11 @@ void test__zmq_z85_decode__zmq_z85_encode__roundtrip (
{
const size_t decoded_size = (SIZE - 1) * 4 / 5;
uint8_t test_data_decoded[decoded_size];
uint8_t *res1 = zmq_z85_decode (test_data_decoded, test_data_);
const uint8_t *const res1 = zmq_z85_decode (test_data_decoded, test_data_);
TEST_ASSERT_NOT_NULL (res1);
char test_data_z85[SIZE];
char *res2 =
const char *const res2 =
zmq_z85_encode (test_data_z85, test_data_decoded, decoded_size);
TEST_ASSERT_NOT_NULL (res2);
......
......@@ -162,8 +162,8 @@ struct poller_test_data_t
void run_poller (void *data_)
{
struct poller_test_data_t *poller_test_data =
static_cast<struct poller_test_data_t *> (data_);
const poller_test_data_t *const poller_test_data =
static_cast<const poller_test_data_t *> (data_);
void *socket =
zmq_socket (poller_test_data->ctx, poller_test_data->socket_type);
......
......@@ -68,7 +68,8 @@ void test_disconnect_inproc ()
zmq_msg_t msg;
zmq_msg_init (&msg);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, pub_socket, 0));
char *buffer = static_cast<char *> (zmq_msg_data (&msg));
const char *const buffer =
static_cast<const char *> (zmq_msg_data (&msg));
if (buffer[0] == 0) {
TEST_ASSERT_TRUE (isSubscribed);
......
......@@ -56,8 +56,7 @@ void test_system_max ()
// System is out of resources, further calls to zmq_socket should return NULL
for (unsigned int i = 0; i < 10; ++i) {
void *socket = zmq_socket (get_test_context (), ZMQ_PAIR);
TEST_ASSERT_NULL (socket);
TEST_ASSERT_NULL (zmq_socket (get_test_context (), ZMQ_PAIR));
}
// Clean up.
for (unsigned int i = 0; i < sockets.size (); ++i)
......@@ -80,8 +79,7 @@ void test_zmq_default_max ()
// Further calls to zmq_socket should return NULL
for (unsigned int i = 0; i < 10; ++i) {
void *socket = zmq_socket (get_test_context (), ZMQ_PAIR);
TEST_ASSERT_NULL (socket);
TEST_ASSERT_NULL (zmq_socket (get_test_context (), ZMQ_PAIR));
}
// Clean up
......
......@@ -80,7 +80,7 @@ void *g_workers_pkts_out = NULL;
static void client_task (void *db_)
{
struct thread_data *databag = static_cast<struct thread_data *> (db_);
const thread_data *const databag = static_cast<const thread_data *> (db_);
// Endpoint socket gets random port to avoid test failing when port in use
void *endpoint = zmq_socket (get_test_context (), ZMQ_PAIR);
TEST_ASSERT_NOT_NULL (endpoint);
......
......@@ -83,7 +83,8 @@ static void lower_hwm (void *skt_)
static void publisher_thread_main (void *pvoid_)
{
proxy_hwm_cfg_t *cfg = static_cast<proxy_hwm_cfg_t *> (pvoid_);
const proxy_hwm_cfg_t *const cfg =
static_cast<const proxy_hwm_cfg_t *> (pvoid_);
void *pubsocket = zmq_socket (cfg->context, ZMQ_XPUB);
assert (pubsocket);
......@@ -138,7 +139,8 @@ static void publisher_thread_main (void *pvoid_)
static void subscriber_thread_main (void *pvoid_)
{
proxy_hwm_cfg_t *cfg = static_cast<proxy_hwm_cfg_t *> (pvoid_);
const proxy_hwm_cfg_t *const cfg =
static_cast<const proxy_hwm_cfg_t *> (pvoid_);
void *subsocket = zmq_socket (cfg->context, ZMQ_SUB);
assert (subsocket);
......@@ -266,8 +268,8 @@ bool check_proxy_stats (void *control_proxy_)
static void proxy_stats_asker_thread_main (void *pvoid_)
{
proxy_hwm_cfg_t *cfg = static_cast<proxy_hwm_cfg_t *> (pvoid_);
const proxy_hwm_cfg_t *const cfg =
static_cast<const proxy_hwm_cfg_t *> (pvoid_);
// CONTROL REQ
......@@ -318,10 +320,10 @@ static void proxy_stats_asker_thread_main (void *pvoid_)
static void proxy_thread_main (void *pvoid_)
{
proxy_hwm_cfg_t *cfg = static_cast<proxy_hwm_cfg_t *> (pvoid_);
const proxy_hwm_cfg_t *const cfg =
static_cast<const proxy_hwm_cfg_t *> (pvoid_);
int rc;
// FRONTEND SUB
void *frontend_xsub = zmq_socket (
......
......@@ -350,7 +350,7 @@ static bool is_multicast_available (int ipv6_)
if (ipv6_) {
struct ipv6_mreq mreq;
struct sockaddr_in6 *mcast_ipv6 = &mcast.ipv6;
const sockaddr_in6 *const mcast_ipv6 = &mcast.ipv6;
mreq.ipv6mr_multiaddr = mcast_ipv6->sin6_addr;
mreq.ipv6mr_interface = 0;
......@@ -369,7 +369,7 @@ static bool is_multicast_available (int ipv6_)
}
} else {
struct ip_mreq mreq;
struct sockaddr_in *mcast_ipv4 = &mcast.ipv4;
const sockaddr_in *const mcast_ipv4 = &mcast.ipv4;
mreq.imr_multiaddr = mcast_ipv4->sin_addr;
mreq.imr_interface.s_addr = htonl (INADDR_ANY);
......
......@@ -203,8 +203,9 @@ static int get_monitor_event (void *monitor_, int *value_, char **address_)
TEST_ASSERT_FALSE (zmq_msg_more (&msg));
if (address_) {
uint8_t *data = static_cast<uint8_t *> (zmq_msg_data (&msg));
size_t size = zmq_msg_size (&msg);
const uint8_t *const data =
static_cast<const uint8_t *> (zmq_msg_data (&msg));
const size_t size = zmq_msg_size (&msg);
*address_ = static_cast<char *> (malloc (size + 1));
memcpy (*address_, data, size);
*address_[size] = 0;
......
......@@ -48,7 +48,7 @@ struct thread_data
extern "C" {
static void worker (void *data_)
{
struct thread_data *tdata = (struct thread_data *) data_;
const thread_data *const tdata = static_cast<const thread_data *> (data_);
void *socket = zmq_socket (get_test_context (), ZMQ_SUB);
......
......@@ -42,8 +42,7 @@ void tearDown ()
// tests all socket-related functions with a NULL socket argument
void test_zmq_socket_null_context ()
{
void *s = zmq_socket (NULL, ZMQ_PAIR);
TEST_ASSERT_NULL (s);
TEST_ASSERT_NULL (zmq_socket (NULL, ZMQ_PAIR));
TEST_ASSERT_EQUAL_INT (EFAULT, errno); // TODO use EINVAL instead?
}
......
......@@ -60,8 +60,9 @@ static int get_monitor_event (void *monitor_, int *value_, char **address_)
TEST_ASSERT_TRUE (!zmq_msg_more (&msg));
if (address_) {
uint8_t *data = static_cast<uint8_t *> (zmq_msg_data (&msg));
size_t size = zmq_msg_size (&msg);
const uint8_t *const data =
static_cast<const uint8_t *> (zmq_msg_data (&msg));
const size_t size = zmq_msg_size (&msg);
*address_ = static_cast<char *> (malloc (size + 1));
memcpy (*address_, data, size);
*address_[size] = 0;
......
......@@ -61,8 +61,9 @@ static int get_monitor_event_internal (void *monitor_,
TEST_ASSERT_FALSE (zmq_msg_more (&msg));
if (address_) {
uint8_t *data = static_cast<uint8_t *> (zmq_msg_data (&msg));
size_t size = zmq_msg_size (&msg);
const uint8_t *const data =
static_cast<const uint8_t *> (zmq_msg_data (&msg));
const size_t size = zmq_msg_size (&msg);
*address_ = static_cast<char *> (malloc (size + 1));
memcpy (*address_, data, size);
(*address_)[size] = 0;
......@@ -246,8 +247,9 @@ static int64_t get_monitor_event_internal_v2 (void *monitor_,
TEST_ASSERT_TRUE (zmq_msg_more (&msg));
if (local_address_) {
uint8_t *data = static_cast<uint8_t *> (zmq_msg_data (&msg));
size_t size = zmq_msg_size (&msg);
const uint8_t *const data =
static_cast<const uint8_t *> (zmq_msg_data (&msg));
const size_t size = zmq_msg_size (&msg);
*local_address_ = static_cast<char *> (malloc (size + 1));
memcpy (*local_address_, data, size);
(*local_address_)[size] = 0;
......@@ -260,8 +262,9 @@ static int64_t get_monitor_event_internal_v2 (void *monitor_,
TEST_ASSERT_TRUE (!zmq_msg_more (&msg));
if (remote_address_) {
uint8_t *data = static_cast<uint8_t *> (zmq_msg_data (&msg));
size_t size = zmq_msg_size (&msg);
const uint8_t *data =
static_cast<const uint8_t *> (zmq_msg_data (&msg));
const size_t size = zmq_msg_size (&msg);
*remote_address_ = static_cast<char *> (malloc (size + 1));
memcpy (*remote_address_, data, size);
(*remote_address_)[size] = 0;
......
......@@ -109,8 +109,8 @@ void socket_config_curve_server (void *server_, void *server_secret_)
void socket_config_curve_client (void *client_, void *data_)
{
curve_client_data_t *curve_client_data =
static_cast<curve_client_data_t *> (data_);
const curve_client_data_t *const curve_client_data =
static_cast<const curve_client_data_t *> (data_);
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (
client_, ZMQ_CURVE_SERVERKEY, curve_client_data->server_public, 41));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment