Commit 440be28d authored by Simon Giesecke's avatar Simon Giesecke

Problem: unnecessary non-const variables

Solution: add const
parent d6952ded
......@@ -166,14 +166,14 @@ void zmq::socks_request_encoder_t::encode (const socks_request_t &req)
const int rc = getaddrinfo (req.hostname.c_str (), NULL, &hints, &res);
if (rc == 0 && res->ai_family == AF_INET) {
struct sockaddr_in *sockaddr_in =
reinterpret_cast<struct sockaddr_in *> (res->ai_addr);
const struct sockaddr_in *sockaddr_in =
reinterpret_cast<const struct sockaddr_in *> (res->ai_addr);
*ptr++ = 0x01;
memcpy (ptr, &sockaddr_in->sin_addr, 4);
ptr += 4;
} else if (rc == 0 && res->ai_family == AF_INET6) {
struct sockaddr_in6 *sockaddr_in6 =
reinterpret_cast<struct sockaddr_in6 *> (res->ai_addr);
const struct sockaddr_in6 *sockaddr_in6 =
reinterpret_cast<const struct sockaddr_in6 *> (res->ai_addr);
*ptr++ = 0x04;
memcpy (ptr, &sockaddr_in6->sin6_addr, 16);
ptr += 16;
......
......@@ -1110,12 +1110,14 @@ int zmq::stream_engine_t::process_heartbeat_message (msg_t *msg_)
int zmq::stream_engine_t::process_command_message (msg_t *msg_)
{
uint8_t cmd_name_size = *(static_cast<uint8_t *> (msg_->data ()));
const uint8_t cmd_name_size =
*(static_cast<const uint8_t *> (msg_->data ()));
// Malformed command
if (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 *cmd_name =
(static_cast<const uint8_t *> (msg_->data ())) + 1;
if (cmd_name_size == 4
&& (memcmp (cmd_name, "PING", cmd_name_size) == 0
|| memcmp (cmd_name, "PONG", cmd_name_size) == 0))
......
......@@ -262,7 +262,7 @@ int zmq::tcp_connecter_t::open ()
return -1;
}
zmq_assert (addr->resolved.tcp_addr != NULL);
tcp_address_t *const tcp_addr = addr->resolved.tcp_addr;
const tcp_address_t *const tcp_addr = addr->resolved.tcp_addr;
// Create the socket.
s = open_socket (tcp_addr->family (), SOCK_STREAM, IPPROTO_TCP);
......
......@@ -285,14 +285,15 @@ void zmq::udp_engine_t::terminate ()
void zmq::udp_engine_t::sockaddr_to_msg (zmq::msg_t *msg, sockaddr_in *addr)
{
char *name = inet_ntoa (addr->sin_addr);
const char *const name = inet_ntoa (addr->sin_addr);
char port[6];
sprintf (port, "%d", static_cast<int> (ntohs (addr->sin_port)));
int size = static_cast<int> (strlen (name))
+ static_cast<int> (strlen (port)) + 1 + 1; // Colon + NULL
int rc = msg->init_size (size);
const int size = static_cast<int> (strlen (name))
+ static_cast<int> (strlen (port)) + 1
+ 1; // Colon + NULL
const int rc = msg->init_size (size);
errno_assert (rc == 0);
msg->set_flags (msg_t::more);
char *address = static_cast<char *> (msg->data ());
......@@ -472,7 +473,8 @@ void zmq::udp_engine_t::in_event ()
body_size = nbytes;
body_offset = 0;
} else {
char *group_buffer = reinterpret_cast<char *> (in_buffer) + 1;
const char *group_buffer =
reinterpret_cast<const char *> (in_buffer) + 1;
int group_size = in_buffer[0];
rc = msg.init_size (group_size);
......
......@@ -89,7 +89,8 @@ void zmq::xpub_t::xread_activated (pipe_t *pipe_)
msg_t sub;
while (pipe_->read (&sub)) {
// Apply the subscription to the trie
unsigned char *const data = static_cast<unsigned char *> (sub.data ());
const unsigned char *const data =
static_cast<const unsigned char *> (sub.data ());
const size_t size = sub.size ();
metadata_t *metadata = sub.metadata ();
if (size > 0 && (*data == 0 || *data == 1)) {
......
......@@ -186,7 +186,7 @@ int zap_client_t::receive_and_process_zap_reply ()
}
// Status code frame, only 200, 300, 400 and 500 are valid status codes
char *status_code_data = static_cast<char *> (msg[3].data ());
const char *status_code_data = static_cast<const char *> (msg[3].data ());
if (msg[3].size () != 3 || status_code_data[0] < '2'
|| status_code_data[0] > '5' || status_code_data[1] != '0'
|| status_code_data[2] != '0') {
......
......@@ -545,7 +545,7 @@ int zmq_recviov (void *s_, iovec *a_, size_t *count_, int flags_)
memcpy (a_[i].iov_base, static_cast<char *> (zmq_msg_data (&msg)),
a_[i].iov_len);
// Assume zmq_socket ZMQ_RVCMORE is properly set.
zmq::msg_t *p_msg = reinterpret_cast<zmq::msg_t *> (&msg);
const zmq::msg_t *p_msg = reinterpret_cast<const zmq::msg_t *> (&msg);
recvmore = p_msg->flags () & zmq::msg_t::more;
rc = zmq_msg_close (&msg);
errno_assert (rc == 0);
......@@ -678,7 +678,8 @@ const char *zmq_msg_group (zmq_msg_t *msg_)
const char *zmq_msg_gets (const zmq_msg_t *msg_, const char *property_)
{
zmq::metadata_t *metadata = ((zmq::msg_t *) msg_)->metadata ();
const zmq::metadata_t *metadata =
reinterpret_cast<const zmq::msg_t *> (msg_)->metadata ();
const char *value = NULL;
if (metadata)
value = metadata->get (std::string (property_));
......@@ -1355,7 +1356,7 @@ int zmq_socket_get_peer_state (void *s_,
const void *routing_id_,
size_t routing_id_size_)
{
zmq::socket_base_t *s = as_socket_base_t (s_);
const zmq::socket_base_t *const s = as_socket_base_t (s_);
if (!s)
return -1;
......
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