diff --git a/src/blob.hpp b/src/blob.hpp index 6abc86ddfe..bdd2ec2b13 100644 --- a/src/blob.hpp +++ b/src/blob.hpp @@ -30,6 +30,8 @@ #ifndef __ZMQ_BLOB_HPP_INCLUDED__ #define __ZMQ_BLOB_HPP_INCLUDED__ +#include "err.hpp" + #include #include #include @@ -73,19 +75,21 @@ struct blob_t // Creates a blob_t of a given size, with uninitialized content. explicit blob_t (const size_t size) : - data_ ((unsigned char *) malloc (size)), + data_ (static_cast (malloc (size))), size_ (size), owned_ (true) { + alloc_assert (data_); } // Creates a blob_t of a given size, an initializes content by copying // from another buffer. blob_t (const unsigned char *const data, const size_t size) : - data_ ((unsigned char *) malloc (size)), + data_ (static_cast (malloc (size))), size_ (size), owned_ (true) { + alloc_assert (data_); memcpy (data_, data, size_); } @@ -120,7 +124,7 @@ struct blob_t void set_deep_copy (blob_t const &other) { clear (); - data_ = (unsigned char *) malloc (other.size_); + data_ = static_cast (malloc (other.size_)); size_ = other.size_; owned_ = true; memcpy (data_, other.data_, size_); @@ -130,7 +134,7 @@ struct blob_t void set (const unsigned char *const data, const size_t size) { clear (); - data_ = (unsigned char *) malloc (size); + data_ = static_cast (malloc (size)); size_ = size; owned_ = true; memcpy (data_, data, size_); diff --git a/src/clock.cpp b/src/clock.cpp index b1aae5877d..dadf9e57d8 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -156,7 +156,7 @@ uint64_t zmq::clock_t::now_us () // Convert the tick number into the number of seconds // since the system was started. double ticks_div = ticksPerSecond.QuadPart / 1000000.0; - return (uint64_t) (tick.QuadPart / ticks_div); + return static_cast (tick.QuadPart / ticks_div); #elif defined HAVE_CLOCK_GETTIME \ && (defined CLOCK_MONOTONIC || defined ZMQ_HAVE_VXWORKS) diff --git a/src/ctx.cpp b/src/ctx.cpp index 7a0c29bfb1..f251e7f56f 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -290,7 +290,8 @@ bool zmq::ctx_t::start () int ios = io_thread_count; opt_sync.unlock (); slot_count = mazmq + ios + 2; - slots = (i_mailbox **) malloc (sizeof (i_mailbox *) * slot_count); + slots = + static_cast (malloc (sizeof (i_mailbox *) * slot_count)); if (!slots) { errno = ENOMEM; goto fail; @@ -311,7 +312,8 @@ bool zmq::ctx_t::start () reaper->start (); // Create I/O thread objects and launch them. - for (int32_t i = (int32_t) slot_count - 1; i >= (int32_t) 2; i--) { + for (int32_t i = static_cast (slot_count) - 1; + i >= static_cast (2); i--) { slots[i] = NULL; } @@ -331,7 +333,8 @@ bool zmq::ctx_t::start () } // In the unused part of the slot array, create a list of empty slots. - for (int32_t i = (int32_t) slot_count - 1; i >= (int32_t) ios + 2; i--) { + for (int32_t i = static_cast (slot_count) - 1; + i >= static_cast (ios) + 2; i--) { empty_slots.push_back (i); } @@ -377,7 +380,7 @@ zmq::socket_base_t *zmq::ctx_t::create_socket (int type_) empty_slots.pop_back (); // Generate new unique socket ID. - int sid = ((int) max_socket_id.add (1)) + 1; + int sid = (static_cast (max_socket_id.add (1))) + 1; // Create the socket and register its mailbox. socket_base_t *s = socket_base_t::create (type_, this, slot, sid); diff --git a/src/curve_client.cpp b/src/curve_client.cpp index dd9102fb72..ab06e20860 100644 --- a/src/curve_client.cpp +++ b/src/curve_client.cpp @@ -176,7 +176,7 @@ int zmq::curve_client_t::produce_initiate (msg_t *msg_) { const size_t metadata_length = basic_properties_len (); unsigned char *metadata_plaintext = - (unsigned char *) malloc (metadata_length); + static_cast (malloc (metadata_length)); alloc_assert (metadata_plaintext); add_basic_properties (metadata_plaintext, metadata_length); @@ -217,10 +217,11 @@ int zmq::curve_client_t::process_ready (const uint8_t *msg_data, const size_t clen = (msg_size - 14) + crypto_box_BOXZEROBYTES; uint8_t ready_nonce[crypto_box_NONCEBYTES]; - uint8_t *ready_plaintext = (uint8_t *) malloc (crypto_box_ZEROBYTES + clen); + uint8_t *ready_plaintext = + static_cast (malloc (crypto_box_ZEROBYTES + clen)); alloc_assert (ready_plaintext); uint8_t *ready_box = - (uint8_t *) malloc (crypto_box_BOXZEROBYTES + 16 + clen); + static_cast (malloc (crypto_box_BOXZEROBYTES + 16 + clen)); alloc_assert (ready_box); memset (ready_box, 0, crypto_box_BOXZEROBYTES); diff --git a/src/curve_client_tools.hpp b/src/curve_client_tools.hpp index 5ca2450118..1ea37d574f 100644 --- a/src/curve_client_tools.hpp +++ b/src/curve_client_tools.hpp @@ -164,11 +164,11 @@ struct curve_client_tools_t return -1; uint8_t initiate_nonce[crypto_box_NONCEBYTES]; - uint8_t *initiate_box = - (uint8_t *) malloc (crypto_box_BOXZEROBYTES + 144 + metadata_length); + uint8_t *initiate_box = static_cast ( + malloc (crypto_box_BOXZEROBYTES + 144 + metadata_length)); alloc_assert (initiate_box); - uint8_t *initiate_plaintext = - (uint8_t *) malloc (crypto_box_ZEROBYTES + 128 + metadata_length); + uint8_t *initiate_plaintext = static_cast ( + malloc (crypto_box_ZEROBYTES + 128 + metadata_length)); alloc_assert (initiate_plaintext); // Create Box [C + vouch + metadata](C'->S') diff --git a/src/curve_server.cpp b/src/curve_server.cpp index 6938a637a1..23649d8f95 100644 --- a/src/curve_server.cpp +++ b/src/curve_server.cpp @@ -430,7 +430,7 @@ int zmq::curve_server_t::produce_ready (msg_t *msg_) uint8_t ready_nonce[crypto_box_NONCEBYTES]; uint8_t *ready_plaintext = - (uint8_t *) malloc (crypto_box_ZEROBYTES + metadata_length); + static_cast (malloc (crypto_box_ZEROBYTES + metadata_length)); alloc_assert (ready_plaintext); // Create Box [metadata](S'->C') @@ -443,8 +443,8 @@ int zmq::curve_server_t::produce_ready (msg_t *msg_) memcpy (ready_nonce, "CurveZMQREADY---", 16); put_uint64 (ready_nonce + 16, cn_nonce); - uint8_t *ready_box = - (uint8_t *) malloc (crypto_box_BOXZEROBYTES + 16 + metadata_length); + uint8_t *ready_box = static_cast ( + malloc (crypto_box_BOXZEROBYTES + 16 + metadata_length)); alloc_assert (ready_box); int rc = crypto_box_afternm (ready_box, ready_plaintext, mlen, ready_nonce, diff --git a/src/dish.cpp b/src/dish.cpp index b45c24e2c9..cf48e5d964 100644 --- a/src/dish.cpp +++ b/src/dish.cpp @@ -295,7 +295,8 @@ int zmq::dish_session_t::push_msg (msg_t *msg_) goto has_group; // Set the message group - rc = msg_->set_group ((char *) group_msg.data (), group_msg.size ()); + rc = msg_->set_group (static_cast (group_msg.data ()), + group_msg.size ()); errno_assert (rc == 0); // We set the group, so we don't need the group_msg anymore @@ -328,7 +329,7 @@ int zmq::dish_session_t::pull_msg (msg_t *msg_) if (!msg_->is_join () && !msg_->is_leave ()) return rc; else { - int group_length = (int) strlen (msg_->group ()); + int group_length = static_cast (strlen (msg_->group ())); msg_t command; int offset; @@ -346,7 +347,7 @@ int zmq::dish_session_t::pull_msg (msg_t *msg_) } command.set_flags (msg_t::command); - char *command_data = (char *) command.data (); + char *command_data = static_cast (command.data ()); // Copy the group memcpy (command_data + offset, msg_->group (), group_length); diff --git a/src/dist.cpp b/src/dist.cpp index a8daf2aad7..fb805103e9 100644 --- a/src/dist.cpp +++ b/src/dist.cpp @@ -179,7 +179,7 @@ void zmq::dist_t::distribute (msg_t *msg_) // Add matching-1 references to the message. We already hold one reference, // that's why -1. - msg_->add_refs ((int) matching - 1); + msg_->add_refs (static_cast (matching) - 1); // Push copy of the message to each matching pipe. int failed = 0; diff --git a/src/encoder.hpp b/src/encoder.hpp index 92b1a2e744..b77038067b 100644 --- a/src/encoder.hpp +++ b/src/encoder.hpp @@ -60,7 +60,7 @@ template class encoder_base_t : public i_encoder next (NULL), new_msg_flag (false), bufsize (bufsize_), - buf ((unsigned char *) malloc (bufsize_)), + buf (static_cast (malloc (bufsize_))), in_progress (NULL) { alloc_assert (buf); @@ -146,7 +146,7 @@ template class encoder_base_t : public i_encoder step_t next_, bool new_msg_flag_) { - write_pos = (unsigned char *) write_pos_; + write_pos = static_cast (write_pos_); to_write = to_write_; next = next_; new_msg_flag = new_msg_flag_; diff --git a/src/err.cpp b/src/err.cpp index ffbc4b3495..da4272d5ea 100644 --- a/src/err.cpp +++ b/src/err.cpp @@ -219,8 +219,8 @@ void zmq::win_error (char *buffer_, size_t buffer_size_) #else DWORD rc = FormatMessageA ( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, - MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), buffer_, (DWORD) buffer_size_, - NULL); + MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), buffer_, + static_cast (buffer_size_), NULL); #endif zmq_assert (rc); } diff --git a/src/err.hpp b/src/err.hpp index 5bda5bb118..ad5c659447 100644 --- a/src/err.hpp +++ b/src/err.hpp @@ -56,7 +56,15 @@ namespace zmq { const char *errno_to_string (int errno_); +#if defined __clang__ +#if __has_feature(attribute_analyzer_noreturn) +void zmq_abort (const char *errmsg_) __attribute__ ((analyzer_noreturn)); +#endif +#elif defined __MSCVER__ +__declspec(noreturn) void zmq_abort (const char *errmsg_); +#else void zmq_abort (const char *errmsg_); +#endif void print_backtrace (void); } diff --git a/src/fd.hpp b/src/fd.hpp index 1317856587..effcc12091 100644 --- a/src/fd.hpp +++ b/src/fd.hpp @@ -49,8 +49,11 @@ enum #else typedef SOCKET fd_t; enum +#if _MSC_VER >= 1800 + : fd_t +#endif { - retired_fd = (fd_t) INVALID_SOCKET + retired_fd = INVALID_SOCKET }; #endif #else diff --git a/src/generic_mtrie_impl.hpp b/src/generic_mtrie_impl.hpp index ef194f3766..b3d03fac79 100644 --- a/src/generic_mtrie_impl.hpp +++ b/src/generic_mtrie_impl.hpp @@ -191,7 +191,7 @@ void zmq::generic_mtrie_t::rm_helper (value_t *pipe_, // Adjust the buffer. if (buffsize_ >= maxbuffsize_) { maxbuffsize_ = buffsize_ + 256; - *buff_ = (unsigned char *) realloc (*buff_, maxbuffsize_); + *buff_ = static_cast (realloc (*buff_, maxbuffsize_)); alloc_assert (*buff_); } diff --git a/src/io_thread.cpp b/src/io_thread.cpp index a70b8ec827..af6bddd0a2 100644 --- a/src/io_thread.cpp +++ b/src/io_thread.cpp @@ -38,7 +38,7 @@ zmq::io_thread_t::io_thread_t (ctx_t *ctx_, uint32_t tid_) : object_t (ctx_, tid_), - mailbox_handle ((poller_t::handle_t) NULL) + mailbox_handle (static_cast (NULL)) { poller = new (std::nothrow) poller_t (*ctx_); alloc_assert (poller); diff --git a/src/ip.cpp b/src/ip.cpp index abc4985885..07edc0570e 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -135,8 +135,8 @@ void zmq::enable_ipv4_mapping (fd_t s_) #else int flag = 0; #endif - int rc = - setsockopt (s_, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &flag, sizeof (flag)); + int rc = setsockopt (s_, IPPROTO_IPV6, IPV6_V6ONLY, + reinterpret_cast (&flag), sizeof (flag)); #ifdef ZMQ_HAVE_WINDOWS wsa_assert (rc != SOCKET_ERROR); #else @@ -156,7 +156,8 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_) #else socklen_t addrlen = sizeof ss; #endif - rc = getpeername (sockfd_, (struct sockaddr *) &ss, &addrlen); + rc = getpeername (sockfd_, reinterpret_cast (&ss), + &addrlen); #ifdef ZMQ_HAVE_WINDOWS if (rc == SOCKET_ERROR) { const int last_error = WSAGetLastError (); @@ -173,8 +174,8 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_) #endif char host[NI_MAXHOST]; - rc = getnameinfo ((struct sockaddr *) &ss, addrlen, host, sizeof host, NULL, - 0, NI_NUMERICHOST); + rc = getnameinfo (reinterpret_cast (&ss), addrlen, host, + sizeof host, NULL, 0, NI_NUMERICHOST); if (rc != 0) return 0; @@ -187,7 +188,7 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_) } u; u.sa_stor = ss; - return (int) u.sa.sa_family; + return static_cast (u.sa.sa_family); } void zmq::set_ip_type_of_service (fd_t s_, int iptos) @@ -311,8 +312,9 @@ void zmq::shutdown_network () static void tune_socket (const SOCKET socket) { BOOL tcp_nodelay = 1; - int rc = setsockopt (socket, IPPROTO_TCP, TCP_NODELAY, - (char *) &tcp_nodelay, sizeof tcp_nodelay); + int rc = + setsockopt (socket, IPPROTO_TCP, TCP_NODELAY, + reinterpret_cast (&tcp_nodelay), sizeof tcp_nodelay); wsa_assert (rc != SOCKET_ERROR); zmq::tcp_tune_loopback_fast_path (socket); @@ -415,7 +417,8 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_) // Set SO_REUSEADDR and TCP_NODELAY on listening socket. BOOL so_reuseaddr = 1; int rc = setsockopt (listener, SOL_SOCKET, SO_REUSEADDR, - (char *) &so_reuseaddr, sizeof so_reuseaddr); + reinterpret_cast (&so_reuseaddr), + sizeof so_reuseaddr); wsa_assert (rc != SOCKET_ERROR); tune_socket (listener); @@ -441,12 +444,14 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_) } // Bind listening socket to signaler port. - rc = bind (listener, (const struct sockaddr *) &addr, sizeof addr); + rc = bind (listener, reinterpret_cast (&addr), + sizeof addr); if (rc != SOCKET_ERROR && signaler_port == 0) { // Retrieve ephemeral port number int addrlen = sizeof addr; - rc = getsockname (listener, (struct sockaddr *) &addr, &addrlen); + rc = getsockname (listener, reinterpret_cast (&addr), + &addrlen); } // Listen for incoming connections. @@ -455,7 +460,8 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_) // Connect writer to the listener. if (rc != SOCKET_ERROR) - rc = connect (*w_, (struct sockaddr *) &addr, sizeof addr); + rc = connect (*w_, reinterpret_cast (&addr), + sizeof addr); // Accept connection from writer. if (rc != SOCKET_ERROR) @@ -466,22 +472,26 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_) if (*r_ != INVALID_SOCKET) { size_t dummy_size = 1024 * 1024; // 1M to overload default receive buffer - unsigned char *dummy = (unsigned char *) malloc (dummy_size); + unsigned char *dummy = + static_cast (malloc (dummy_size)); wsa_assert (dummy); - int still_to_send = (int) dummy_size; - int still_to_recv = (int) dummy_size; + int still_to_send = static_cast (dummy_size); + int still_to_recv = static_cast (dummy_size); while (still_to_send || still_to_recv) { int nbytes; if (still_to_send > 0) { - nbytes = - ::send (*w_, (char *) (dummy + dummy_size - still_to_send), - still_to_send, 0); + nbytes = ::send ( + *w_, + reinterpret_cast (dummy + dummy_size - still_to_send), + still_to_send, 0); wsa_assert (nbytes != SOCKET_ERROR); still_to_send -= nbytes; } - nbytes = ::recv (*r_, (char *) (dummy + dummy_size - still_to_recv), - still_to_recv, 0); + nbytes = ::recv ( + *r_, + reinterpret_cast (dummy + dummy_size - still_to_recv), + still_to_recv, 0); wsa_assert (nbytes != SOCKET_ERROR); still_to_recv -= nbytes; } diff --git a/src/ip_resolver.cpp b/src/ip_resolver.cpp index fcaf62bfa7..ec2500927e 100644 --- a/src/ip_resolver.cpp +++ b/src/ip_resolver.cpp @@ -208,7 +208,7 @@ int zmq::ip_resolver_t::resolve (ip_addr_t *ip_addr_, const char *name_) port = 0; } else { // Parse the port number (0 is not a valid port). - port = (uint16_t) atoi (port_str.c_str ()); + port = static_cast (atoi (port_str.c_str ())); if (port == 0) { errno = EINVAL; return -1; @@ -239,7 +239,7 @@ int zmq::ip_resolver_t::resolve (ip_addr_t *ip_addr_, const char *name_) if (isalpha (if_str.at (0))) { zone_id = do_if_nametoindex (if_str.c_str ()); } else { - zone_id = (uint32_t) atoi (if_str.c_str ()); + zone_id = static_cast (atoi (if_str.c_str ())); } if (zone_id == 0) { @@ -557,7 +557,7 @@ int zmq::ip_resolver_t::get_interface_name (unsigned long index, #ifdef ZMQ_HAVE_WINDOWS_UWP char *buffer = (char *) malloc (1024); #else - char *buffer = (char *) malloc (IF_MAX_STRING_SIZE); + char *buffer = static_cast (malloc (IF_MAX_STRING_SIZE)); #endif alloc_assert (buffer); @@ -582,7 +582,7 @@ int zmq::ip_resolver_t::wchar_to_utf8 (const WCHAR *src, char **dest) const int buffer_len = WideCharToMultiByte (CP_UTF8, 0, src, -1, NULL, 0, NULL, 0); - char *buffer = (char *) malloc (buffer_len); + char *buffer = static_cast (malloc (buffer_len)); alloc_assert (buffer); rc = WideCharToMultiByte (CP_UTF8, 0, src, -1, buffer, buffer_len, NULL, 0); @@ -608,7 +608,7 @@ int zmq::ip_resolver_t::resolve_nic_name (ip_addr_t *ip_addr_, const char *nic_) unsigned long out_buf_len = sizeof (IP_ADAPTER_ADDRESSES); do { - addresses = (IP_ADAPTER_ADDRESSES *) malloc (out_buf_len); + addresses = static_cast (malloc (out_buf_len)); alloc_assert (addresses); rc = diff --git a/src/mechanism.cpp b/src/mechanism.cpp index e4abb1a44c..2dabb378e1 100644 --- a/src/mechanism.cpp +++ b/src/mechanism.cpp @@ -209,14 +209,14 @@ void zmq::mechanism_t::make_command_with_basic_properties ( const int rc = msg_->init_size (command_size); errno_assert (rc == 0); - unsigned char *ptr = (unsigned char *) msg_->data (); + unsigned char *ptr = static_cast (msg_->data ()); // Add prefix memcpy (ptr, prefix_, prefix_len_); ptr += prefix_len_; - add_basic_properties (ptr, command_size - - (ptr - (unsigned char *) msg_->data ())); + add_basic_properties ( + ptr, command_size - (ptr - static_cast (msg_->data ()))); } int zmq::mechanism_t::parse_metadata (const unsigned char *ptr_, @@ -251,7 +251,8 @@ int zmq::mechanism_t::parse_metadata (const unsigned char *ptr_, if (name == ZMTP_PROPERTY_IDENTITY && options.recv_routing_id) set_peer_routing_id (value, value_length); else if (name == ZMTP_PROPERTY_SOCKET_TYPE) { - if (!check_socket_type ((const char *) value, value_length)) { + if (!check_socket_type (reinterpret_cast (value), + value_length)) { errno = EINVAL; return -1; } diff --git a/src/mechanism_base.cpp b/src/mechanism_base.cpp index 6063c7a73e..bc2e0ac77b 100644 --- a/src/mechanism_base.cpp +++ b/src/mechanism_base.cpp @@ -41,7 +41,8 @@ zmq::mechanism_base_t::mechanism_base_t (session_base_t *const session_, int zmq::mechanism_base_t::check_basic_command_structure (msg_t *msg_) { - if (msg_->size () <= 1 || msg_->size () <= ((uint8_t *) msg_->data ())[0]) { + if (msg_->size () <= 1 + || msg_->size () <= (static_cast (msg_->data ()))[0]) { session->get_socket ()->event_handshake_failed_protocol ( session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_UNSPECIFIED); diff --git a/src/msg.cpp b/src/msg.cpp index 6ef040d9ef..40fce163bc 100644 --- a/src/msg.cpp +++ b/src/msg.cpp @@ -88,7 +88,7 @@ int zmq::msg_t::init_size (size_t size_) u.vsm.metadata = NULL; u.vsm.type = type_vsm; u.vsm.flags = 0; - u.vsm.size = (unsigned char) size_; + u.vsm.size = static_cast (size_); u.vsm.group[0] = '\0'; u.vsm.routing_id = 0; } else { @@ -99,7 +99,8 @@ int zmq::msg_t::init_size (size_t size_) u.lmsg.routing_id = 0; u.lmsg.content = NULL; if (sizeof (content_t) + size_ > size_) - u.lmsg.content = (content_t *) malloc (sizeof (content_t) + size_); + u.lmsg.content = + static_cast (malloc (sizeof (content_t) + size_)); if (unlikely (!u.lmsg.content)) { errno = ENOMEM; return -1; @@ -163,7 +164,7 @@ int zmq::msg_t::init_data (void *data_, u.lmsg.flags = 0; u.lmsg.group[0] = '\0'; u.lmsg.routing_id = 0; - u.lmsg.content = (content_t *) malloc (sizeof (content_t)); + u.lmsg.content = static_cast (malloc (sizeof (content_t))); if (!u.lmsg.content) { errno = ENOMEM; return -1; diff --git a/src/options.cpp b/src/options.cpp index 27702317ba..5628fb60a4 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -75,7 +75,8 @@ int zmq::do_getsockopt (void *const optval_, } memcpy (optval_, value_, value_len_); // TODO why is the remaining memory null-ed? - memset ((char *) optval_ + value_len_, 0, *optvallen_ - value_len_); + memset (static_cast (optval_) + value_len_, 0, + *optvallen_ - value_len_); *optvallen_ = value_len_; return 0; } @@ -89,7 +90,8 @@ static int do_getsockopt_curve_key (void *const optval_, memcpy (optval_, curve_key_, CURVE_KEYSIZE); return 0; } else if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) { - zmq_z85_encode ((char *) optval_, curve_key_, CURVE_KEYSIZE); + zmq_z85_encode (static_cast (optval_), curve_key_, + CURVE_KEYSIZE); return 0; } return sockopt_invalid (); @@ -148,7 +150,7 @@ do_setsockopt_string_allow_empty_strict (const void *const optval_, out_value_->clear (); return 0; } else if (optval_ != NULL && optvallen_ > 0 && optvallen_ <= max_len_) { - out_value_->assign ((const char *) optval_, optvallen_); + out_value_->assign (static_cast (optval_), optvallen_); return 0; } return sockopt_invalid (); @@ -163,7 +165,7 @@ do_setsockopt_string_allow_empty_relaxed (const void *const optval_, // TODO use either do_setsockopt_string_allow_empty_relaxed or // do_setsockopt_string_allow_empty_strict everywhere if (optvallen_ > 0 && optvallen_ <= max_len_) { - out_value_->assign ((const char *) optval_, optvallen_); + out_value_->assign (static_cast (optval_), optvallen_); return 0; } return sockopt_invalid (); @@ -312,7 +314,7 @@ int zmq::options_t::setsockopt (int option_, case ZMQ_ROUTING_ID: // Routing id is any binary string from 1 to 255 octets if (optvallen_ > 0 && optvallen_ < 256) { - routing_id_size = (unsigned char) optvallen_; + routing_id_size = static_cast (optvallen_); memcpy (routing_id, optval_, routing_id_size); return 0; } @@ -529,7 +531,8 @@ int zmq::options_t::setsockopt (int option_, mechanism = ZMQ_NULL; return 0; } else if (optvallen_ > 0 && optvallen_ < 256 && optval_ != NULL) { - plain_username.assign ((const char *) optval_, optvallen_); + plain_username.assign (static_cast (optval_), + optvallen_); as_server = 0; mechanism = ZMQ_PLAIN; return 0; @@ -541,7 +544,8 @@ int zmq::options_t::setsockopt (int option_, mechanism = ZMQ_NULL; return 0; } else if (optvallen_ > 0 && optvallen_ < 256 && optval_ != NULL) { - plain_password.assign ((const char *) optval_, optvallen_); + plain_password.assign (static_cast (optval_), + optvallen_); as_server = 0; mechanism = ZMQ_PLAIN; return 0; @@ -662,7 +666,7 @@ int zmq::options_t::setsockopt (int option_, // Convert this to deciseconds from milliseconds value = value / 100; if (is_int && value >= 0 && value <= 6553) { - heartbeat_ttl = (uint16_t) value; + heartbeat_ttl = static_cast (value); return 0; } break; @@ -764,7 +768,7 @@ int zmq::options_t::getsockopt (int option_, size_t *optvallen_) const { bool is_int = (*optvallen_ == sizeof (int)); - int *value = (int *) optval_; + int *value = static_cast (optval_); #if defined(ZMQ_ACT_MILITANT) bool malformed = true; // Did caller pass a bad option value? #endif @@ -786,7 +790,7 @@ int zmq::options_t::getsockopt (int option_, case ZMQ_AFFINITY: if (*optvallen_ == sizeof (uint64_t)) { - *((uint64_t *) optval_) = affinity; + *(static_cast (optval_)) = affinity; return 0; } break; @@ -882,7 +886,7 @@ int zmq::options_t::getsockopt (int option_, case ZMQ_MAXMSGSIZE: if (*optvallen_ == sizeof (int64_t)) { - *((int64_t *) optval_) = maxmsgsize; + *(static_cast (optval_)) = maxmsgsize; *optvallen_ = sizeof (int64_t); return 0; } diff --git a/src/options.hpp b/src/options.hpp index 8390acac2b..e4a96ca266 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -103,7 +103,7 @@ struct options_t int tos; // Socket type. - int type; + int8_t type; // Linger time, in milliseconds. atomic_value_t linger; diff --git a/src/own.cpp b/src/own.cpp index b5933bb87f..82f4187230 100644 --- a/src/own.cpp +++ b/src/own.cpp @@ -163,7 +163,7 @@ void zmq::own_t::process_term (int linger_) // Send termination request to all owned objects. for (owned_t::iterator it = owned.begin (); it != owned.end (); ++it) send_term (*it, linger_); - register_term_acks ((int) owned.size ()); + register_term_acks (static_cast (owned.size ())); owned.clear (); // Start termination process and check whether by chance we cannot diff --git a/src/pipe.cpp b/src/pipe.cpp index a52ea1c47f..0c2a7c35d2 100644 --- a/src/pipe.cpp +++ b/src/pipe.cpp @@ -181,20 +181,21 @@ bool zmq::pipe_t::read (msg_t *msg_) if (unlikely (state != active && state != waiting_for_delimiter)) return false; -read_message: - if (!inpipe->read (msg_)) { - in_active = false; - return false; - } + for (bool payload_read = false; !payload_read;) { + if (!inpipe->read (msg_)) { + in_active = false; + return false; + } - // If this is a credential, save a copy and receive next message. - if (unlikely (msg_->is_credential ())) { - const unsigned char *data = - static_cast (msg_->data ()); - credential.set (data, msg_->size ()); - const int rc = msg_->close (); - zmq_assert (rc == 0); - goto read_message; + // If this is a credential, save a copy and receive next message. + if (unlikely (msg_->is_credential ())) { + const unsigned char *data = + static_cast (msg_->data ()); + credential.set (data, msg_->size ()); + const int rc = msg_->close (); + zmq_assert (rc == 0); + } else + payload_read = true; } // If delimiter was read, start termination process of the pipe. @@ -300,7 +301,7 @@ void zmq::pipe_t::process_hiccup (void *pipe_) // Plug in the new outpipe. zmq_assert (pipe_); - outpipe = (upipe_t *) pipe_; + outpipe = static_cast (pipe_); out_active = true; // If appropriate, notify the user about the hiccup. diff --git a/src/plain_server.cpp b/src/plain_server.cpp index c47cfe0e87..b9536593e1 100644 --- a/src/plain_server.cpp +++ b/src/plain_server.cpp @@ -241,7 +241,7 @@ int zmq::plain_server_t::produce_error (msg_t *msg_) const zmq_assert (rc == 0); char *msg_data = static_cast (msg_->data ()); memcpy (msg_data, "\5ERROR", 6); - msg_data[6] = (char) status_code.length (); + msg_data[6] = static_cast (status_code.length ()); memcpy (msg_data + 7, status_code.c_str (), status_code.length ()); return 0; } diff --git a/src/poller_base.cpp b/src/poller_base.cpp index 8221310221..307ab57964 100644 --- a/src/poller_base.cpp +++ b/src/poller_base.cpp @@ -132,5 +132,5 @@ void zmq::worker_poller_base_t::check_thread () void zmq::worker_poller_base_t::worker_routine (void *arg_) { - ((worker_poller_base_t *) arg_)->loop (); + (static_cast (arg_))->loop (); } diff --git a/src/radio.cpp b/src/radio.cpp index ed1ff4c14a..a09c6c8cd9 100644 --- a/src/radio.cpp +++ b/src/radio.cpp @@ -215,11 +215,11 @@ int zmq::radio_session_t::push_msg (msg_t *msg_) // Set the msg type to either JOIN or LEAVE if (data_size >= 5 && memcmp (command_data, "\4JOIN", 5) == 0) { - group_length = (int) data_size - 5; + group_length = static_cast (data_size) - 5; group = command_data + 5; rc = join_leave_msg.init_join (); } else if (data_size >= 6 && memcmp (command_data, "\5LEAVE", 6) == 0) { - group_length = (int) data_size - 6; + group_length = static_cast (data_size) - 6; group = command_data + 6; rc = join_leave_msg.init_leave (); } @@ -252,7 +252,7 @@ int zmq::radio_session_t::pull_msg (msg_t *msg_) return rc; const char *group = pending_msg.group (); - int length = (int) strlen (group); + int length = static_cast (strlen (group)); // First frame is the group rc = msg_->init_size (length); diff --git a/src/random.cpp b/src/random.cpp index e8a648a160..e783470e0b 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -49,18 +49,18 @@ void zmq::seed_random () { #if defined ZMQ_HAVE_WINDOWS - int pid = (int) GetCurrentProcessId (); + int pid = static_cast (GetCurrentProcessId ()); #else int pid = (int) getpid (); #endif - srand ((unsigned int) (clock_t::now_us () + pid)); + srand (static_cast (clock_t::now_us () + pid)); } uint32_t zmq::generate_random () { // Compensate for the fact that rand() returns signed integer. - uint32_t low = (uint32_t) rand (); - uint32_t high = (uint32_t) rand (); + uint32_t low = static_cast (rand ()); + uint32_t high = static_cast (rand ()); high <<= (sizeof (int) * 8 - 1); return high | low; } diff --git a/src/raw_decoder.cpp b/src/raw_decoder.cpp index 7cb2e67ebc..18a0ae7b7b 100644 --- a/src/raw_decoder.cpp +++ b/src/raw_decoder.cpp @@ -57,7 +57,7 @@ int zmq::raw_decoder_t::decode (const uint8_t *data_, size_t &bytes_used_) { int rc = - in_progress.init ((unsigned char *) data_, size_, + in_progress.init (const_cast (data_), size_, shared_message_memory_allocator::call_dec_ref, allocator.buffer (), allocator.provide_content ()); diff --git a/src/reaper.cpp b/src/reaper.cpp index 5dcf14a74a..bc96403a7d 100644 --- a/src/reaper.cpp +++ b/src/reaper.cpp @@ -35,7 +35,7 @@ zmq::reaper_t::reaper_t (class ctx_t *ctx_, uint32_t tid_) : object_t (ctx_, tid_), - mailbox_handle ((poller_t::handle_t) NULL), + mailbox_handle (static_cast (NULL)), poller (NULL), sockets (0), terminating (false) diff --git a/src/req.cpp b/src/req.cpp index 969ee46d31..f9c15718a7 100644 --- a/src/req.cpp +++ b/src/req.cpp @@ -82,7 +82,8 @@ int zmq::req_t::xsend (msg_t *msg_) request_id++; // Copy request id before sending (see issue #1695 for details). - uint32_t *request_id_copy = (uint32_t *) malloc (sizeof (uint32_t)); + uint32_t *request_id_copy = + static_cast (malloc (sizeof (uint32_t))); zmq_assert (request_id_copy); *request_id_copy = request_id; diff --git a/src/router.cpp b/src/router.cpp index 7b0450663f..4d29bbdab2 100644 --- a/src/router.cpp +++ b/src/router.cpp @@ -212,8 +212,8 @@ int zmq::router_t::xsend (msg_t *msg_) // Find the pipe associated with the routing id stored in the prefix. // If there's no such pipe just silently ignore the message, unless // router_mandatory is set. - blob_t routing_id ((unsigned char *) msg_->data (), msg_->size (), - zmq::reference_tag_t ()); + blob_t routing_id (static_cast (msg_->data ()), + msg_->size (), zmq::reference_tag_t ()); outpipes_t::iterator it = outpipes.find (routing_id); if (it != outpipes.end ()) { @@ -498,7 +498,8 @@ bool zmq::router_t::identify_peer (pipe_t *pipe_) routing_id.set (buf, sizeof buf); msg.close (); } else { - routing_id.set ((unsigned char *) msg.data (), msg.size ()); + routing_id.set (static_cast (msg.data ()), + msg.size ()); outpipes_t::iterator it = outpipes.find (routing_id); msg.close (); diff --git a/src/select.cpp b/src/select.cpp index af8f0d7ef2..7d0c113714 100644 --- a/src/select.cpp +++ b/src/select.cpp @@ -295,7 +295,7 @@ void zmq::select_t::loop () { while (true) { // Execute any due timers. - int timeout = (int) execute_timers (); + int timeout = static_cast (execute_timers ()); cleanup_retired (); @@ -316,8 +316,8 @@ void zmq::select_t::loop () #if defined ZMQ_HAVE_OSX struct timeval tv = {(long) (timeout / 1000), timeout % 1000 * 1000}; #else - struct timeval tv = {(long) (timeout / 1000), - (long) (timeout % 1000 * 1000)}; + struct timeval tv = {static_cast (timeout / 1000), + static_cast (timeout % 1000 * 1000)}; #endif #if defined ZMQ_HAVE_WINDOWS @@ -577,14 +577,15 @@ u_short zmq::select_t::determine_fd_family (fd_t fd_) int type; int type_length = sizeof (int); - int rc = - getsockopt (fd_, SOL_SOCKET, SO_TYPE, (char *) &type, &type_length); + int rc = getsockopt (fd_, SOL_SOCKET, SO_TYPE, + reinterpret_cast (&type), &type_length); if (rc == 0) { if (type == SOCK_DGRAM) return AF_INET; else { - rc = getsockname (fd_, (sockaddr *) &addr, &addr_size); + rc = getsockname (fd_, reinterpret_cast (&addr), + &addr_size); // AF_INET and AF_INET6 can be mixed in select // TODO: If proven otherwise, should simply return addr.sa_family diff --git a/src/signaler.cpp b/src/signaler.cpp index 0fb7764921..acc261d4ef 100644 --- a/src/signaler.cpp +++ b/src/signaler.cpp @@ -143,7 +143,8 @@ zmq::signaler_t::~signaler_t () if (w != retired_fd) { const struct linger so_linger = {1, 0}; int rc = setsockopt (w, SOL_SOCKET, SO_LINGER, - (const char *) &so_linger, sizeof so_linger); + reinterpret_cast (&so_linger), + sizeof so_linger); // Only check shutdown if WSASTARTUP was previously done if (rc == 0 || WSAGetLastError () != WSANOTINITIALISED) { wsa_assert (rc != SOCKET_ERROR); @@ -187,7 +188,8 @@ void zmq::signaler_t::send () #elif defined ZMQ_HAVE_WINDOWS unsigned char dummy = 0; while (true) { - int nbytes = ::send (w, (char *) &dummy, sizeof (dummy), 0); + int nbytes = + ::send (w, reinterpret_cast (&dummy), sizeof (dummy), 0); wsa_assert (nbytes != SOCKET_ERROR); if (unlikely (nbytes == SOCKET_ERROR)) continue; @@ -319,7 +321,8 @@ void zmq::signaler_t::recv () #else unsigned char dummy; #if defined ZMQ_HAVE_WINDOWS - int nbytes = ::recv (r, (char *) &dummy, sizeof (dummy), 0); + int nbytes = + ::recv (r, reinterpret_cast (&dummy), sizeof (dummy), 0); wsa_assert (nbytes != SOCKET_ERROR); #elif defined ZMQ_HAVE_VXWORKS ssize_t nbytes = ::recv (r, (char *) &dummy, sizeof (dummy), 0); @@ -359,7 +362,8 @@ int zmq::signaler_t::recv_failable () #else unsigned char dummy; #if defined ZMQ_HAVE_WINDOWS - int nbytes = ::recv (r, (char *) &dummy, sizeof (dummy), 0); + int nbytes = + ::recv (r, reinterpret_cast (&dummy), sizeof (dummy), 0); if (nbytes == SOCKET_ERROR) { const int last_error = WSAGetLastError (); if (last_error == WSAEWOULDBLOCK) { diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 29e9e2faef..3bf82ae732 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -196,7 +196,7 @@ zmq::socket_base_t::socket_base_t (ctx_t *parent_, ctx_terminated (false), destroyed (false), poller (NULL), - handle ((poller_t::handle_t) NULL), + handle (static_cast (NULL)), last_tsc (0), ticks (0), rcvmore (false), @@ -410,8 +410,8 @@ int zmq::socket_base_t::getsockopt (int option_, return -1; } - return do_getsockopt (optval_, optvallen_, - ((mailbox_t *) mailbox)->get_fd ()); + return do_getsockopt ( + optval_, optvallen_, (static_cast (mailbox))->get_fd ()); } if (option_ == ZMQ_EVENTS) { @@ -462,7 +462,7 @@ void zmq::socket_base_t::add_signaler (signaler_t *s_) zmq_assert (thread_safe); scoped_lock_t sync_lock (sync); - ((mailbox_safe_t *) mailbox)->add_signaler (s_); + (static_cast (mailbox))->add_signaler (s_); } void zmq::socket_base_t::remove_signaler (signaler_t *s_) @@ -470,7 +470,7 @@ void zmq::socket_base_t::remove_signaler (signaler_t *s_) zmq_assert (thread_safe); scoped_lock_t sync_lock (sync); - ((mailbox_safe_t *) mailbox)->remove_signaler (s_); + (static_cast (mailbox))->remove_signaler (s_); } int zmq::socket_base_t::bind (const char *addr_) @@ -1146,7 +1146,7 @@ int zmq::socket_base_t::send (msg_t *msg_, int flags_) return -1; } if (timeout > 0) { - timeout = (int) (end - clock.now_ms ()); + timeout = static_cast (end - clock.now_ms ()); if (timeout <= 0) { errno = EAGAIN; return -1; @@ -1241,7 +1241,7 @@ int zmq::socket_base_t::recv (msg_t *msg_, int flags_) } block = true; if (timeout > 0) { - timeout = (int) (end - clock.now_ms ()); + timeout = static_cast (end - clock.now_ms ()); if (timeout <= 0) { errno = EAGAIN; return -1; @@ -1259,7 +1259,7 @@ int zmq::socket_base_t::close () // Remove all existing signalers for thread safe sockets if (thread_safe) - ((mailbox_safe_t *) mailbox)->clear_signalers (); + (static_cast (mailbox))->clear_signalers (); // Mark the socket as dead tag = 0xdeadbeef; @@ -1291,7 +1291,7 @@ void zmq::socket_base_t::start_reaping (poller_t *poller_) fd_t fd; if (!thread_safe) - fd = ((mailbox_t *) mailbox)->get_fd (); + fd = (static_cast (mailbox))->get_fd (); else { scoped_optional_lock_t sync_lock (thread_safe ? &sync : NULL); @@ -1300,7 +1300,8 @@ void zmq::socket_base_t::start_reaping (poller_t *poller_) // Add signaler to the safe mailbox fd = reaper_signaler->get_fd (); - ((mailbox_safe_t *) mailbox)->add_signaler (reaper_signaler); + (static_cast (mailbox)) + ->add_signaler (reaper_signaler); // Send a signal to make sure reaper handle existing commands reaper_signaler->send (); @@ -1394,7 +1395,7 @@ void zmq::socket_base_t::process_term (int linger_) // Ask all attached pipes to terminate. for (pipes_t::size_type i = 0; i != pipes.size (); ++i) pipes[i]->terminate (false); - register_term_acks ((int) pipes.size ()); + register_term_acks (static_cast (pipes.size ())); // Continue the termination process immediately. own_t::process_term (linger_); @@ -1730,10 +1731,10 @@ void zmq::socket_base_t::monitor_event (int event_, // Send event in first frame zmq_msg_t msg; zmq_msg_init_size (&msg, 6); - uint8_t *data = (uint8_t *) zmq_msg_data (&msg); + uint8_t *data = static_cast (zmq_msg_data (&msg)); // Avoid dereferencing uint32_t on unaligned address - uint16_t event = (uint16_t) event_; - uint32_t value = (uint32_t) value_; + uint16_t event = static_cast (event_); + uint32_t value = static_cast (value_); memcpy (data + 0, &event, sizeof (event)); memcpy (data + 2, &value, sizeof (value)); zmq_sendmsg (monitor_socket, &msg, ZMQ_SNDMORE); diff --git a/src/socket_poller.cpp b/src/socket_poller.cpp index d0629ce54c..c1c99f5835 100644 --- a/src/socket_poller.cpp +++ b/src/socket_poller.cpp @@ -630,8 +630,8 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, } else if (timeout_ < 0) ptimeout = NULL; else { - timeout.tv_sec = (long) ((end - now) / 1000); - timeout.tv_usec = (long) ((end - now) % 1000 * 1000); + timeout.tv_sec = static_cast ((end - now) / 1000); + timeout.tv_usec = static_cast ((end - now) % 1000 * 1000); ptimeout = &timeout; } @@ -643,14 +643,17 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, // We just need to copy fd_count elements of fd_array. // We gain huge memcpy() improvement if number of used SOCKETs is much lower than FD_SETSIZE. memcpy (&inset, &pollset_in, - (char *) (pollset_in.fd_array + pollset_in.fd_count) - - (char *) &pollset_in); + reinterpret_cast (pollset_in.fd_array + + pollset_in.fd_count) + - reinterpret_cast (&pollset_in)); memcpy (&outset, &pollset_out, - (char *) (pollset_out.fd_array + pollset_out.fd_count) - - (char *) &pollset_out); + reinterpret_cast (pollset_out.fd_array + + pollset_out.fd_count) + - reinterpret_cast (&pollset_out)); memcpy (&errset, &pollset_err, - (char *) (pollset_err.fd_array + pollset_err.fd_count) - - (char *) &pollset_err); + reinterpret_cast (pollset_err.fd_array + + pollset_err.fd_count) + - reinterpret_cast (&pollset_err)); int rc = select (0, &inset, &outset, &errset, ptimeout); if (unlikely (rc == SOCKET_ERROR)) { errno = zmq::wsa_error_to_errno (WSAGetLastError ()); diff --git a/src/socks.cpp b/src/socks.cpp index 148d76f1a9..3e71b26480 100644 --- a/src/socks.cpp +++ b/src/socks.cpp @@ -64,7 +64,7 @@ void zmq::socks_greeting_encoder_t::encode (const socks_greeting_t &greeting_) uint8_t *ptr = buf; *ptr++ = 0x05; - *ptr++ = (uint8_t) greeting_.num_methods; + *ptr++ = static_cast (greeting_.num_methods); for (uint8_t i = 0; i < greeting_.num_methods; i++) *ptr++ = greeting_.methods[i]; @@ -179,7 +179,7 @@ void zmq::socks_request_encoder_t::encode (const socks_request_t &req) ptr += 16; } else { *ptr++ = 0x03; - *ptr++ = (unsigned char) req.hostname.size (); + *ptr++ = static_cast (req.hostname.size ()); memcpy (ptr, req.hostname.c_str (), req.hostname.size ()); ptr += req.hostname.size (); } diff --git a/src/socks_connecter.cpp b/src/socks_connecter.cpp index 7dfc8a8570..ca6d56f441 100644 --- a/src/socks_connecter.cpp +++ b/src/socks_connecter.cpp @@ -64,7 +64,7 @@ zmq::socks_connecter_t::socks_connecter_t (class io_thread_t *io_thread_, proxy_addr (proxy_addr_), status (unplugged), s (retired_fd), - handle ((handle_t) NULL), + handle (static_cast (NULL)), handle_valid (false), delayed_start (delayed_start_), timer_started (false), @@ -178,7 +178,7 @@ void zmq::socks_connecter_t::out_event () || status == sending_greeting || status == sending_request); if (status == waiting_for_proxy_connection) { - const int rc = (int) check_proxy_connection (); + const int rc = static_cast (check_proxy_connection ()); if (rc == -1) error (); else { @@ -394,7 +394,8 @@ zmq::fd_t zmq::socks_connecter_t::check_proxy_connection () socklen_t len = sizeof err; #endif - int rc = getsockopt (s, SOL_SOCKET, SO_ERROR, (char *) &err, &len); + int rc = getsockopt (s, SOL_SOCKET, SO_ERROR, + reinterpret_cast (&err), &len); // Assert if the error was caused by 0MQ bug. // Networking problems are OK. No need to assert. @@ -468,7 +469,7 @@ int zmq::socks_connecter_t::parse_address (const std::string &address_, // Separate the hostname/port. const std::string port_str = address_.substr (idx + 1); // Parse the port number (0 is not a valid port). - port_ = (uint16_t) atoi (port_str.c_str ()); + port_ = static_cast (atoi (port_str.c_str ())); if (port_ == 0) { errno = EINVAL; return -1; diff --git a/src/stream.cpp b/src/stream.cpp index cefb45f38b..9c3c412802 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -108,7 +108,8 @@ int zmq::stream_t::xsend (msg_t *msg_) if (msg_->flags () & msg_t::more) { // Find the pipe associated with the routing id stored in the prefix. // If there's no such pipe return an error - blob_t routing_id ((unsigned char *) msg_->data (), msg_->size ()); + blob_t routing_id (static_cast (msg_->data ()), + msg_->size ()); outpipes_t::iterator it = outpipes.find (routing_id); if (it != outpipes.end ()) { @@ -302,7 +303,8 @@ void zmq::stream_t::identify_peer (pipe_t *pipe_) put_uint32 (buffer + 1, next_integral_routing_id++); routing_id.set (buffer, sizeof buffer); memcpy (options.routing_id, routing_id.data (), routing_id.size ()); - options.routing_id_size = (unsigned char) routing_id.size (); + options.routing_id_size = + static_cast (routing_id.size ()); } pipe_->set_router_socket_routing_id (routing_id); // Add the record into output pipes lookup table diff --git a/src/stream_engine.cpp b/src/stream_engine.cpp index 103e54ae21..028a59e3d6 100644 --- a/src/stream_engine.cpp +++ b/src/stream_engine.cpp @@ -67,7 +67,7 @@ zmq::stream_engine_t::stream_engine_t (fd_t fd_, const std::string &endpoint_) : s (fd_), as_server (false), - handle ((handle_t) NULL), + handle (static_cast (NULL)), inpos (NULL), insize (0), decoder (NULL), @@ -378,7 +378,7 @@ void zmq::stream_engine_t::out_event () outpos = NULL; outsize = encoder->encode (&outpos, 0); - while (outsize < (size_t) out_batch_size) { + while (outsize < static_cast (out_batch_size)) { if ((this->*next_msg) (&tx_msg) == -1) break; encoder->load_msg (&tx_msg); @@ -753,7 +753,7 @@ int zmq::stream_engine_t::process_routing_id_msg (msg_t *msg_) // ZMQ 2.x peers receive published messages. int rc = subscription.init_size (1); errno_assert (rc == 0); - *(unsigned char *) subscription.data () = 1; + *static_cast (subscription.data ()) = 1; rc = session->push_msg (&subscription); errno_assert (rc == 0); } @@ -1004,7 +1004,7 @@ bool zmq::stream_engine_t::init_properties (properties_t &properties) // Private property to support deprecated SRCFD std::ostringstream stream; - stream << (int) s; + stream << static_cast (s); std::string fd_string = stream.str (); properties.ZMQ_MAP_INSERT_OR_EMPLACE (std::string ("__fd"), ZMQ_MOVE (fd_string)); @@ -1045,7 +1045,8 @@ int zmq::stream_engine_t::produce_ping_message (msg_t *msg_) memcpy (msg_->data (), "\4PING", 5); uint16_t ttl_val = htons (options.heartbeat_ttl); - memcpy (((uint8_t *) msg_->data ()) + 5, &ttl_val, sizeof (ttl_val)); + memcpy ((static_cast (msg_->data ())) + 5, &ttl_val, + sizeof (ttl_val)); rc = mechanism->encode (msg_); next_msg = &stream_engine_t::pull_and_encode; @@ -1074,7 +1075,8 @@ int zmq::stream_engine_t::process_heartbeat_message (msg_t *msg_) if (memcmp (msg_->data (), "\4PING", 5) == 0) { uint16_t remote_heartbeat_ttl; // Get the remote heartbeat TTL to setup the timer - memcpy (&remote_heartbeat_ttl, (uint8_t *) msg_->data () + 5, 2); + memcpy (&remote_heartbeat_ttl, + static_cast (msg_->data ()) + 5, 2); remote_heartbeat_ttl = ntohs (remote_heartbeat_ttl); // The remote heartbeat is in 10ths of a second // so we multiply it by 100 to get the timer interval in ms. @@ -1096,8 +1098,8 @@ int zmq::stream_engine_t::process_heartbeat_message (msg_t *msg_) pong_msg.set_flags (msg_t::command); memcpy (pong_msg.data (), "\4PONG", 5); if (context_len > 0) - memcpy (((uint8_t *) pong_msg.data ()) + 5, - ((uint8_t *) msg_->data ()) + 7, context_len); + memcpy ((static_cast (pong_msg.data ())) + 5, + (static_cast (msg_->data ())) + 7, context_len); next_msg = &stream_engine_t::produce_pong_message; out_event (); @@ -1108,12 +1110,12 @@ 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 = *((uint8_t *) msg_->data ()); + uint8_t cmd_name_size = *(static_cast (msg_->data ())); // Malformed command if (msg_->size () < cmd_name_size + sizeof (cmd_name_size)) return -1; - uint8_t *cmd_name = ((uint8_t *) msg_->data ()) + 1; + uint8_t *cmd_name = (static_cast (msg_->data ())) + 1; if (cmd_name_size == 4 && (memcmp (cmd_name, "PING", cmd_name_size) == 0 || memcmp (cmd_name, "PONG", cmd_name_size) == 0)) diff --git a/src/sub.cpp b/src/sub.cpp index 7a7e6e71db..e235360d78 100644 --- a/src/sub.cpp +++ b/src/sub.cpp @@ -58,7 +58,7 @@ int zmq::sub_t::xsetsockopt (int option_, msg_t msg; int rc = msg.init_size (optvallen_ + 1); errno_assert (rc == 0); - unsigned char *data = (unsigned char *) msg.data (); + unsigned char *data = static_cast (msg.data ()); *data = (option_ == ZMQ_SUBSCRIBE); // We explicitly allow a NULL subscription with size zero if (optvallen_) { diff --git a/src/tcp.cpp b/src/tcp.cpp index fd9b6ad0d7..e1b5b485b2 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -54,8 +54,8 @@ int zmq::tune_tcp_socket (fd_t s_) // so using Nagle wouldn't improve throughput in anyway, but it would // hurt latency. int nodelay = 1; - int rc = setsockopt (s_, IPPROTO_TCP, TCP_NODELAY, (char *) &nodelay, - sizeof (int)); + int rc = setsockopt (s_, IPPROTO_TCP, TCP_NODELAY, + reinterpret_cast (&nodelay), sizeof (int)); tcp_assert_tuning_error (s_, rc); if (rc != 0) return rc; @@ -72,16 +72,18 @@ int zmq::tune_tcp_socket (fd_t s_) int zmq::set_tcp_send_buffer (fd_t sockfd_, int bufsize_) { - const int rc = setsockopt (sockfd_, SOL_SOCKET, SO_SNDBUF, - (char *) &bufsize_, sizeof bufsize_); + const int rc = + setsockopt (sockfd_, SOL_SOCKET, SO_SNDBUF, + reinterpret_cast (&bufsize_), sizeof bufsize_); tcp_assert_tuning_error (sockfd_, rc); return rc; } int zmq::set_tcp_receive_buffer (fd_t sockfd_, int bufsize_) { - const int rc = setsockopt (sockfd_, SOL_SOCKET, SO_RCVBUF, - (char *) &bufsize_, sizeof bufsize_); + const int rc = + setsockopt (sockfd_, SOL_SOCKET, SO_RCVBUF, + reinterpret_cast (&bufsize_), sizeof bufsize_); tcp_assert_tuning_error (sockfd_, rc); return rc; } @@ -184,8 +186,9 @@ int zmq::tune_tcp_maxrt (fd_t sockfd_, int timeout_) #if defined(ZMQ_HAVE_WINDOWS) && defined(TCP_MAXRT) // msdn says it's supported in >= Vista, >= Windows Server 2003 timeout_ /= 1000; // in seconds - int rc = setsockopt (sockfd_, IPPROTO_TCP, TCP_MAXRT, (char *) &timeout_, - sizeof (timeout_)); + int rc = + setsockopt (sockfd_, IPPROTO_TCP, TCP_MAXRT, + reinterpret_cast (&timeout_), sizeof (timeout_)); tcp_assert_tuning_error (sockfd_, rc); return rc; // FIXME: should be ZMQ_HAVE_TCP_USER_TIMEOUT @@ -194,15 +197,16 @@ int zmq::tune_tcp_maxrt (fd_t sockfd_, int timeout_) sizeof (timeout_)); tcp_assert_tuning_error (sockfd_, rc); return rc; -#endif +#else return 0; +#endif } int zmq::tcp_write (fd_t s_, const void *data_, size_t size_) { #ifdef ZMQ_HAVE_WINDOWS - int nbytes = send (s_, (char *) data_, (int) size_, 0); + int nbytes = send (s_, (char *) data_, static_cast (size_), 0); // If not a single byte can be written to the socket in non-blocking mode // we'll get an error (this may happen during the speculative write). @@ -254,7 +258,8 @@ int zmq::tcp_read (fd_t s_, void *data_, size_t size_) { #ifdef ZMQ_HAVE_WINDOWS - const int rc = recv (s_, (char *) data_, (int) size_, 0); + const int rc = + recv (s_, static_cast (data_), static_cast (size_), 0); // If not a single byte can be read from the socket in non-blocking mode // we'll get an error (this may happen during the speculative read). @@ -306,7 +311,8 @@ void zmq::tcp_assert_tuning_error (zmq::fd_t s_, int rc_) socklen_t len = sizeof err; #endif - int rc = getsockopt (s_, SOL_SOCKET, SO_ERROR, (char *) &err, &len); + int rc = getsockopt (s_, SOL_SOCKET, SO_ERROR, + reinterpret_cast (&err), &len); // Assert if the error was caused by 0MQ bug. // Networking problems are OK. No need to assert. diff --git a/src/tcp_address.cpp b/src/tcp_address.cpp index 1c76268e2d..55a88d0de0 100644 --- a/src/tcp_address.cpp +++ b/src/tcp_address.cpp @@ -61,10 +61,11 @@ zmq::tcp_address_t::tcp_address_t (const sockaddr *sa, socklen_t sa_len) : memset (&address, 0, sizeof (address)); memset (&source_address, 0, sizeof (source_address)); - if (sa->sa_family == AF_INET && sa_len >= (socklen_t) sizeof (address.ipv4)) + if (sa->sa_family == AF_INET + && sa_len >= static_cast (sizeof (address.ipv4))) memcpy (&address.ipv4, sa, sizeof (address.ipv4)); else if (sa->sa_family == AF_INET6 - && sa_len >= (socklen_t) sizeof (address.ipv6)) + && sa_len >= static_cast (sizeof (address.ipv6))) memcpy (&address.ipv6, sa, sizeof (address.ipv6)); } @@ -151,9 +152,9 @@ const sockaddr *zmq::tcp_address_t::addr () const socklen_t zmq::tcp_address_t::addrlen () const { if (address.generic.sa_family == AF_INET6) - return (socklen_t) sizeof (address.ipv6); + return static_cast (sizeof (address.ipv6)); else - return (socklen_t) sizeof (address.ipv4); + return static_cast (sizeof (address.ipv4)); } const sockaddr *zmq::tcp_address_t::src_addr () const @@ -164,9 +165,9 @@ const sockaddr *zmq::tcp_address_t::src_addr () const socklen_t zmq::tcp_address_t::src_addrlen () const { if (address.family () == AF_INET6) - return (socklen_t) sizeof (source_address.ipv6); + return static_cast (sizeof (source_address.ipv6)); else - return (socklen_t) sizeof (source_address.ipv4); + return static_cast (sizeof (source_address.ipv4)); } bool zmq::tcp_address_t::has_src_addr () const @@ -291,15 +292,17 @@ bool zmq::tcp_address_mask_t::match_address (const struct sockaddr *ss, const uint8_t *our_bytes, *their_bytes; if (ss->sa_family == AF_INET6) { zmq_assert (ss_len == sizeof (struct sockaddr_in6)); - their_bytes = (const uint8_t *) &( - ((const struct sockaddr_in6 *) ss)->sin6_addr); - our_bytes = (const uint8_t *) &address.ipv6.sin6_addr; + their_bytes = reinterpret_cast (&( + (reinterpret_cast (ss))->sin6_addr)); + our_bytes = + reinterpret_cast (&address.ipv6.sin6_addr); mask = sizeof (struct in6_addr) * 8; } else { zmq_assert (ss_len == sizeof (struct sockaddr_in)); - their_bytes = - (const uint8_t *) &(((const struct sockaddr_in *) ss)->sin_addr); - our_bytes = (const uint8_t *) &address.ipv4.sin_addr; + their_bytes = reinterpret_cast ( + &((reinterpret_cast (ss))->sin_addr)); + our_bytes = + reinterpret_cast (&address.ipv4.sin_addr); mask = sizeof (struct in_addr) * 8; } if (address_mask < mask) diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp index 0a2068e98b..833e379e75 100644 --- a/src/tcp_connecter.cpp +++ b/src/tcp_connecter.cpp @@ -69,7 +69,7 @@ zmq::tcp_connecter_t::tcp_connecter_t (class io_thread_t *io_thread_, io_object_t (io_thread_), addr (addr_), s (retired_fd), - handle ((handle_t) NULL), + handle (static_cast (NULL)), delayed_start (delayed_start_), connect_timer_started (false), reconnect_timer_started (false), @@ -166,7 +166,7 @@ void zmq::tcp_connecter_t::out_event () void zmq::tcp_connecter_t::rm_handle () { rm_fd (handle); - handle = (handle_t) NULL; + handle = static_cast (NULL); } void zmq::tcp_connecter_t::timer_event (int id_) @@ -325,8 +325,8 @@ int zmq::tcp_connecter_t::open () // using the same source port on the client. int flag = 1; #ifdef ZMQ_HAVE_WINDOWS - rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (const char *) &flag, - sizeof (int)); + rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, + reinterpret_cast (&flag), sizeof (int)); wsa_assert (rc != SOCKET_ERROR); #elif defined ZMQ_HAVE_VXWORKS rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *) &flag, @@ -383,7 +383,8 @@ zmq::fd_t zmq::tcp_connecter_t::connect () socklen_t len = sizeof err; #endif - const int rc = getsockopt (s, SOL_SOCKET, SO_ERROR, (char *) &err, &len); + const int rc = getsockopt (s, SOL_SOCKET, SO_ERROR, + reinterpret_cast (&err), &len); // Assert if the error was caused by 0MQ bug. // Networking problems are OK. No need to assert. diff --git a/src/tcp_listener.cpp b/src/tcp_listener.cpp index 0b0b3b313c..a9b036134e 100644 --- a/src/tcp_listener.cpp +++ b/src/tcp_listener.cpp @@ -66,7 +66,7 @@ zmq::tcp_listener_t::tcp_listener_t (io_thread_t *io_thread_, own_t (io_thread_, options_), io_object_t (io_thread_), s (retired_fd), - handle ((handle_t) NULL), + handle (static_cast (NULL)), socket (socket_) { } @@ -87,7 +87,7 @@ void zmq::tcp_listener_t::process_plug () void zmq::tcp_listener_t::process_term (int linger_) { rm_fd (handle); - handle = (handle_t) NULL; + handle = static_cast (NULL); close (); own_t::process_term (linger_); } @@ -157,14 +157,14 @@ int zmq::tcp_listener_t::get_address (std::string &addr_) #else socklen_t sl = sizeof (ss); #endif - int rc = getsockname (s, (struct sockaddr *) &ss, &sl); + int rc = getsockname (s, reinterpret_cast (&ss), &sl); if (rc != 0) { addr_.clear (); return rc; } - tcp_address_t addr ((struct sockaddr *) &ss, sl); + tcp_address_t addr (reinterpret_cast (&ss), sl); return addr.to_string (addr_); } @@ -236,8 +236,8 @@ int zmq::tcp_listener_t::set_address (const char *addr_) // Allow reusing of the address. int flag = 1; #ifdef ZMQ_HAVE_WINDOWS - rc = setsockopt (s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (const char *) &flag, - sizeof (int)); + rc = setsockopt (s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, + reinterpret_cast (&flag), sizeof (int)); wsa_assert (rc != SOCKET_ERROR); #elif defined ZMQ_HAVE_VXWORKS rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *) &flag, sizeof (int)); @@ -302,7 +302,8 @@ zmq::fd_t zmq::tcp_listener_t::accept () #if defined ZMQ_HAVE_SOCK_CLOEXEC && defined HAVE_ACCEPT4 fd_t sock = ::accept4 (s, (struct sockaddr *) &ss, &ss_len, SOCK_CLOEXEC); #else - fd_t sock = ::accept (s, (struct sockaddr *) &ss, &ss_len); + fd_t sock = + ::accept (s, reinterpret_cast (&ss), &ss_len); #endif #ifdef ZMQ_HAVE_WINDOWS diff --git a/src/timers.cpp b/src/timers.cpp index 61336bec75..a98e47d61c 100644 --- a/src/timers.cpp +++ b/src/timers.cpp @@ -146,7 +146,7 @@ long zmq::timers_t::timeout () // Live timer, lets return the timeout if (cancelled_it == cancelled_timers.end ()) { if (it->first > now) - return (long) (it->first - now); + return static_cast (it->first - now); else return 0; } diff --git a/src/trie.cpp b/src/trie.cpp index 60b513f838..3430875a35 100644 --- a/src/trie.cpp +++ b/src/trie.cpp @@ -74,7 +74,8 @@ bool zmq::trie_t::add (unsigned char *prefix_, size_t size_) unsigned char oldc = min; trie_t *oldp = next.node; count = (min < c ? c - min : min - c) + 1; - next.table = (trie_t **) malloc (sizeof (trie_t *) * count); + next.table = + static_cast (malloc (sizeof (trie_t *) * count)); alloc_assert (next.table); for (unsigned short i = 0; i != count; ++i) next.table[i] = 0; @@ -84,8 +85,8 @@ bool zmq::trie_t::add (unsigned char *prefix_, size_t size_) // The new character is above the current character range. unsigned short old_count = count; count = c - min + 1; - next.table = (trie_t **) realloc ((void *) next.table, - sizeof (trie_t *) * count); + next.table = static_cast ( + realloc ((void *) next.table, sizeof (trie_t *) * count)); zmq_assert (next.table); for (unsigned short i = old_count; i != count; i++) next.table[i] = NULL; @@ -93,8 +94,8 @@ bool zmq::trie_t::add (unsigned char *prefix_, size_t size_) // The new character is below the current character range. unsigned short old_count = count; count = (min + old_count) - c; - next.table = (trie_t **) realloc ((void *) next.table, - sizeof (trie_t *) * count); + next.table = static_cast ( + realloc ((void *) next.table, sizeof (trie_t *) * count)); zmq_assert (next.table); memmove (next.table + min - c, next.table, old_count * sizeof (trie_t *)); @@ -200,7 +201,8 @@ bool zmq::trie_t::rm (unsigned char *prefix_, size_t size_) zmq_assert (count > new_min - min); count = count - (new_min - min); - next.table = (trie_t **) malloc (sizeof (trie_t *) * count); + next.table = + static_cast (malloc (sizeof (trie_t *) * count)); alloc_assert (next.table); memmove (next.table, old_table + (new_min - min), @@ -223,7 +225,8 @@ bool zmq::trie_t::rm (unsigned char *prefix_, size_t size_) count = new_count; trie_t **old_table = next.table; - next.table = (trie_t **) malloc (sizeof (trie_t *) * count); + next.table = + static_cast (malloc (sizeof (trie_t *) * count)); alloc_assert (next.table); memmove (next.table, old_table, sizeof (trie_t *) * count); @@ -290,7 +293,7 @@ void zmq::trie_t::apply_helper (unsigned char **buff_, // Adjust the buffer. if (buffsize_ >= maxbuffsize_) { maxbuffsize_ = buffsize_ + 256; - *buff_ = (unsigned char *) realloc (*buff_, maxbuffsize_); + *buff_ = static_cast (realloc (*buff_, maxbuffsize_)); zmq_assert (*buff_); } diff --git a/src/udp_engine.cpp b/src/udp_engine.cpp index f40a0c5653..53e9a65301 100644 --- a/src/udp_engine.cpp +++ b/src/udp_engine.cpp @@ -55,7 +55,7 @@ zmq::udp_engine_t::udp_engine_t (const options_t &options_) : plugged (false), fd (-1), session (NULL), - handle ((handle_t) NULL), + handle (static_cast (NULL)), address (NULL), options (options_), send_enabled (false), @@ -135,8 +135,9 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) } int loop = options.multicast_loop; - int rc = setsockopt (fd, level, optname, (char *) &loop, - sizeof (loop)); + int rc = + setsockopt (fd, level, optname, + reinterpret_cast (&loop), sizeof (loop)); #ifdef ZMQ_HAVE_WINDOWS wsa_assert (rc != SOCKET_ERROR); @@ -151,7 +152,8 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) // If a bind interface is provided we tell the // kernel to use it to send multicast packets rc = setsockopt (fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, - (char *) &bind_if, sizeof (bind_if)); + reinterpret_cast (&bind_if), + sizeof (bind_if)); } else { rc = 0; } @@ -160,9 +162,9 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) udp_addr->bind_addr ()->ipv4.sin_addr; if (bind_addr.s_addr != INADDR_ANY) { - rc = - setsockopt (fd, IPPROTO_IP, IP_MULTICAST_IF, - (char *) &bind_addr, sizeof (bind_addr)); + rc = setsockopt (fd, IPPROTO_IP, IP_MULTICAST_IF, + reinterpret_cast (&bind_addr), + sizeof (bind_addr)); } else { rc = 0; } @@ -176,7 +178,7 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) } } else { /// XXX fixme ? - out_address = (sockaddr *) &raw_address; + out_address = reinterpret_cast (&raw_address); out_addrlen = sizeof (sockaddr_in); } @@ -185,8 +187,8 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) if (recv_enabled) { int on = 1; - int rc = - setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)); + int rc = setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, + reinterpret_cast (&on), sizeof (on)); #ifdef ZMQ_HAVE_WINDOWS wsa_assert (rc != SOCKET_ERROR); #else @@ -231,8 +233,9 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) mreq.imr_multiaddr = mcast_addr->ipv4.sin_addr; mreq.imr_interface = bind_addr->ipv4.sin_addr; - rc = setsockopt (fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, - (char *) &mreq, sizeof (mreq)); + rc = + setsockopt (fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, + reinterpret_cast (&mreq), sizeof (mreq)); errno_assert (rc == 0); } else if (mcast_addr->family () == AF_INET6) { @@ -244,8 +247,9 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) mreq.ipv6mr_multiaddr = mcast_addr->ipv6.sin6_addr; mreq.ipv6mr_interface = iface; - rc = setsockopt (fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, - (char *) &mreq, sizeof (mreq)); + rc = + setsockopt (fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, + reinterpret_cast (&mreq), sizeof (mreq)); errno_assert (rc == 0); } else { @@ -284,14 +288,14 @@ void zmq::udp_engine_t::sockaddr_to_msg (zmq::msg_t *msg, sockaddr_in *addr) char *name = inet_ntoa (addr->sin_addr); char port[6]; - sprintf (port, "%d", (int) ntohs (addr->sin_port)); + sprintf (port, "%d", static_cast (ntohs (addr->sin_port))); - int size = - (int) strlen (name) + (int) strlen (port) + 1 + 1; // Colon + NULL + int size = static_cast (strlen (name)) + + static_cast (strlen (port)) + 1 + 1; // Colon + NULL int rc = msg->init_size (size); errno_assert (rc == 0); msg->set_flags (msg_t::more); - char *address = (char *) msg->data (); + char *address = static_cast (msg->data ()); strcpy (address, name); strcat (address, ":"); @@ -306,7 +310,7 @@ int zmq::udp_engine_t::resolve_raw_address (char *name_, size_t length_) // Find delimiter, cannot use memrchr as it is not supported on windows if (length_ != 0) { - int chars_left = (int) length_; + int chars_left = static_cast (length_); char *current_char = name_ + length_; do { if (*(--current_char) == ':') { @@ -325,7 +329,7 @@ int zmq::udp_engine_t::resolve_raw_address (char *name_, size_t length_) std::string port_str (delimiter + 1, name_ + length_ - delimiter - 1); // Parse the port number (0 is not a valid port). - uint16_t port = (uint16_t) atoi (port_str.c_str ()); + uint16_t port = static_cast (atoi (port_str.c_str ())); if (port == 0) { errno = EINVAL; return -1; @@ -358,7 +362,8 @@ void zmq::udp_engine_t::out_event () size_t size; if (options.raw_socket) { - rc = resolve_raw_address ((char *) group_msg.data (), group_size); + rc = resolve_raw_address (static_cast (group_msg.data ()), + group_size); // We discard the message if address is not valid if (rc != 0) { @@ -378,7 +383,7 @@ void zmq::udp_engine_t::out_event () size = group_size + body_size + 1; // TODO: check if larger than maximum size - out_buffer[0] = (unsigned char) group_size; + out_buffer[0] = static_cast (group_size); memcpy (out_buffer + 1, group_msg.data (), group_size); memcpy (out_buffer + 1 + group_size, body_msg.data (), body_size); } @@ -390,8 +395,9 @@ void zmq::udp_engine_t::out_event () errno_assert (rc == 0); #ifdef ZMQ_HAVE_WINDOWS - rc = sendto (fd, (const char *) out_buffer, (int) size, 0, out_address, - (int) out_addrlen); + rc = sendto (fd, reinterpret_cast (out_buffer), + static_cast (size), 0, out_address, + static_cast (out_addrlen)); wsa_assert (rc != SOCKET_ERROR); #elif defined ZMQ_HAVE_VXWORKS rc = sendto (fd, (caddr_t) out_buffer, size, 0, @@ -428,8 +434,9 @@ void zmq::udp_engine_t::in_event () sockaddr_storage in_address; socklen_t in_addrlen = sizeof (sockaddr_storage); #ifdef ZMQ_HAVE_WINDOWS - int nbytes = recvfrom (fd, (char *) in_buffer, MAX_UDP_MSG, 0, - (sockaddr *) &in_address, &in_addrlen); + int nbytes = + recvfrom (fd, reinterpret_cast (in_buffer), MAX_UDP_MSG, 0, + reinterpret_cast (&in_address), &in_addrlen); const int last_error = WSAGetLastError (); if (nbytes == SOCKET_ERROR) { wsa_assert (last_error == WSAENETDOWN || last_error == WSAENETRESET @@ -465,7 +472,7 @@ void zmq::udp_engine_t::in_event () body_size = nbytes; body_offset = 0; } else { - char *group_buffer = (char *) in_buffer + 1; + char *group_buffer = reinterpret_cast (in_buffer) + 1; int group_size = in_buffer[0]; rc = msg.init_size (group_size); diff --git a/src/v1_decoder.cpp b/src/v1_decoder.cpp index 8964569c2c..9a090c30f0 100644 --- a/src/v1_decoder.cpp +++ b/src/v1_decoder.cpp @@ -70,7 +70,8 @@ int zmq::v1_decoder_t::one_byte_size_ready (unsigned char const *) return -1; } - if (maxmsgsize >= 0 && (int64_t) (*tmpbuf - 1) > maxmsgsize) { + if (maxmsgsize >= 0 + && static_cast (*tmpbuf - 1) > maxmsgsize) { errno = EMSGSIZE; return -1; } @@ -104,7 +105,8 @@ int zmq::v1_decoder_t::eight_byte_size_ready (unsigned char const *) } // Message size must not exceed the maximum allowed size. - if (maxmsgsize >= 0 && payload_length - 1 > (uint64_t) maxmsgsize) { + if (maxmsgsize >= 0 + && payload_length - 1 > static_cast (maxmsgsize)) { errno = EMSGSIZE; return -1; } diff --git a/src/v1_encoder.cpp b/src/v1_encoder.cpp index c7e37c63c0..e9ce969610 100644 --- a/src/v1_encoder.cpp +++ b/src/v1_encoder.cpp @@ -63,7 +63,7 @@ void zmq::v1_encoder_t::message_ready () // For longer messages write 0xff escape character followed by 8-byte // message size. In both cases 'flags' field follows. if (size < 255) { - tmpbuf[0] = (unsigned char) size; + tmpbuf[0] = static_cast (size); tmpbuf[1] = (in_progress->flags () & msg_t::more); next_step (tmpbuf, 2, &v1_encoder_t::size_ready, false); } else { diff --git a/src/v2_decoder.cpp b/src/v2_decoder.cpp index 839be9ab2b..fe4de910a3 100644 --- a/src/v2_decoder.cpp +++ b/src/v2_decoder.cpp @@ -124,7 +124,7 @@ int zmq::v2_decoder_t::size_ready (uint64_t msg_size, // construct message using n bytes from the buffer as storage // increase buffer ref count // if the message will be a large message, pass a valid refcnt memory location as well - rc = in_progress.init ((unsigned char *) read_pos, + rc = in_progress.init (const_cast (read_pos), static_cast (msg_size), shared_message_memory_allocator::call_dec_ref, buffer (), provide_content ()); diff --git a/src/wire.hpp b/src/wire.hpp index f3158885f8..71591f011e 100644 --- a/src/wire.hpp +++ b/src/wire.hpp @@ -49,47 +49,54 @@ inline uint8_t get_uint8 (const unsigned char *buffer_) inline void put_uint16 (unsigned char *buffer_, uint16_t value) { - buffer_[0] = (unsigned char) (((value) >> 8) & 0xff); - buffer_[1] = (unsigned char) (value & 0xff); + buffer_[0] = static_cast (((value) >> 8) & 0xff); + buffer_[1] = static_cast (value & 0xff); } inline uint16_t get_uint16 (const unsigned char *buffer_) { - return (((uint16_t) buffer_[0]) << 8) | ((uint16_t) buffer_[1]); + return ((static_cast (buffer_[0])) << 8) + | (static_cast (buffer_[1])); } inline void put_uint32 (unsigned char *buffer_, uint32_t value) { - buffer_[0] = (unsigned char) (((value) >> 24) & 0xff); - buffer_[1] = (unsigned char) (((value) >> 16) & 0xff); - buffer_[2] = (unsigned char) (((value) >> 8) & 0xff); - buffer_[3] = (unsigned char) (value & 0xff); + buffer_[0] = static_cast (((value) >> 24) & 0xff); + buffer_[1] = static_cast (((value) >> 16) & 0xff); + buffer_[2] = static_cast (((value) >> 8) & 0xff); + buffer_[3] = static_cast (value & 0xff); } inline uint32_t get_uint32 (const unsigned char *buffer_) { - return (((uint32_t) buffer_[0]) << 24) | (((uint32_t) buffer_[1]) << 16) - | (((uint32_t) buffer_[2]) << 8) | ((uint32_t) buffer_[3]); + return ((static_cast (buffer_[0])) << 24) + | ((static_cast (buffer_[1])) << 16) + | ((static_cast (buffer_[2])) << 8) + | (static_cast (buffer_[3])); } inline void put_uint64 (unsigned char *buffer_, uint64_t value) { - buffer_[0] = (unsigned char) (((value) >> 56) & 0xff); - buffer_[1] = (unsigned char) (((value) >> 48) & 0xff); - buffer_[2] = (unsigned char) (((value) >> 40) & 0xff); - buffer_[3] = (unsigned char) (((value) >> 32) & 0xff); - buffer_[4] = (unsigned char) (((value) >> 24) & 0xff); - buffer_[5] = (unsigned char) (((value) >> 16) & 0xff); - buffer_[6] = (unsigned char) (((value) >> 8) & 0xff); - buffer_[7] = (unsigned char) (value & 0xff); + buffer_[0] = static_cast (((value) >> 56) & 0xff); + buffer_[1] = static_cast (((value) >> 48) & 0xff); + buffer_[2] = static_cast (((value) >> 40) & 0xff); + buffer_[3] = static_cast (((value) >> 32) & 0xff); + buffer_[4] = static_cast (((value) >> 24) & 0xff); + buffer_[5] = static_cast (((value) >> 16) & 0xff); + buffer_[6] = static_cast (((value) >> 8) & 0xff); + buffer_[7] = static_cast (value & 0xff); } inline uint64_t get_uint64 (const unsigned char *buffer_) { - return (((uint64_t) buffer_[0]) << 56) | (((uint64_t) buffer_[1]) << 48) - | (((uint64_t) buffer_[2]) << 40) | (((uint64_t) buffer_[3]) << 32) - | (((uint64_t) buffer_[4]) << 24) | (((uint64_t) buffer_[5]) << 16) - | (((uint64_t) buffer_[6]) << 8) | ((uint64_t) buffer_[7]); + return ((static_cast (buffer_[0])) << 56) + | ((static_cast (buffer_[1])) << 48) + | ((static_cast (buffer_[2])) << 40) + | ((static_cast (buffer_[3])) << 32) + | ((static_cast (buffer_[4])) << 24) + | ((static_cast (buffer_[5])) << 16) + | ((static_cast (buffer_[6])) << 8) + | (static_cast (buffer_[7])); } } diff --git a/src/xpub.cpp b/src/xpub.cpp index 03baa2dac1..717ddbfe5f 100644 --- a/src/xpub.cpp +++ b/src/xpub.cpp @@ -89,7 +89,7 @@ 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 = (unsigned char *) sub.data (); + unsigned char *const data = static_cast (sub.data ()); const size_t size = sub.size (); metadata_t *metadata = sub.metadata (); if (size > 0 && (*data == 0 || *data == 1)) { @@ -183,7 +183,8 @@ int zmq::xpub_t::xsetsockopt (int option_, int rc = welcome_msg.init_size (optvallen_); errno_assert (rc == 0); - unsigned char *data = (unsigned char *) welcome_msg.data (); + unsigned char *data = + static_cast (welcome_msg.data ()); memcpy (data, optval_, optvallen_); } else welcome_msg.init (); @@ -232,8 +233,8 @@ int zmq::xpub_t::xsend (msg_t *msg_) // For the first part of multi-part message, find the matching pipes. if (!more) { - subscriptions.match ((unsigned char *) msg_->data (), msg_->size (), - mark_as_matching, this); + subscriptions.match (static_cast (msg_->data ()), + msg_->size (), mark_as_matching, this); // If inverted matching is used, reverse the selection now if (options.invert_matching) { dist.reverse_match (); diff --git a/src/xsub.cpp b/src/xsub.cpp index 86df5bf71e..d49d3be17c 100644 --- a/src/xsub.cpp +++ b/src/xsub.cpp @@ -94,7 +94,7 @@ void zmq::xsub_t::xhiccuped (pipe_t *pipe_) int zmq::xsub_t::xsend (msg_t *msg_) { size_t size = msg_->size (); - unsigned char *data = (unsigned char *) msg_->data (); + unsigned char *data = static_cast (msg_->data ()); if (size > 0 && *data == 1) { // Process subscribe message @@ -212,8 +212,8 @@ const zmq::blob_t &zmq::xsub_t::get_credential () const bool zmq::xsub_t::match (msg_t *msg_) { - bool matching = - subscriptions.check ((unsigned char *) msg_->data (), msg_->size ()); + bool matching = subscriptions.check ( + static_cast (msg_->data ()), msg_->size ()); return matching ^ options.invert_matching; } @@ -222,13 +222,13 @@ void zmq::xsub_t::send_subscription (unsigned char *data_, size_t size_, void *arg_) { - pipe_t *pipe = (pipe_t *) arg_; + pipe_t *pipe = static_cast (arg_); // Create the subscription message. msg_t msg; int rc = msg.init_size (size_ + 1); errno_assert (rc == 0); - unsigned char *data = (unsigned char *) msg.data (); + unsigned char *data = static_cast (msg.data ()); data[0] = 1; // We explicitly allow a NULL subscription with size zero diff --git a/src/zmq.cpp b/src/zmq.cpp index 1f121ebc64..5fe5834219 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -144,12 +144,12 @@ void *zmq_ctx_new (void) int zmq_ctx_term (void *ctx_) { - if (!ctx_ || !((zmq::ctx_t *) ctx_)->check_tag ()) { + if (!ctx_ || !(static_cast (ctx_))->check_tag ()) { errno = EFAULT; return -1; } - int rc = ((zmq::ctx_t *) ctx_)->terminate (); + int rc = (static_cast (ctx_))->terminate (); int en = errno; // Shut down only if termination was not interrupted by a signal. @@ -163,29 +163,29 @@ int zmq_ctx_term (void *ctx_) int zmq_ctx_shutdown (void *ctx_) { - if (!ctx_ || !((zmq::ctx_t *) ctx_)->check_tag ()) { + if (!ctx_ || !(static_cast (ctx_))->check_tag ()) { errno = EFAULT; return -1; } - return ((zmq::ctx_t *) ctx_)->shutdown (); + return (static_cast (ctx_))->shutdown (); } int zmq_ctx_set (void *ctx_, int option_, int optval_) { - if (!ctx_ || !((zmq::ctx_t *) ctx_)->check_tag ()) { + if (!ctx_ || !(static_cast (ctx_))->check_tag ()) { errno = EFAULT; return -1; } - return ((zmq::ctx_t *) ctx_)->set (option_, optval_); + return (static_cast (ctx_))->set (option_, optval_); } int zmq_ctx_get (void *ctx_, int option_) { - if (!ctx_ || !((zmq::ctx_t *) ctx_)->check_tag ()) { + if (!ctx_ || !(static_cast (ctx_))->check_tag ()) { errno = EFAULT; return -1; } - return ((zmq::ctx_t *) ctx_)->get (option_); + return (static_cast (ctx_))->get (option_); } // Stable/legacy context API @@ -226,11 +226,11 @@ static zmq::socket_base_t *as_socket_base_t (void *s_) void *zmq_socket (void *ctx_, int type_) { - if (!ctx_ || !((zmq::ctx_t *) ctx_)->check_tag ()) { + if (!ctx_ || !(static_cast (ctx_))->check_tag ()) { errno = EFAULT; return NULL; } - zmq::ctx_t *ctx = (zmq::ctx_t *) ctx_; + zmq::ctx_t *ctx = static_cast (ctx_); zmq::socket_base_t *s = ctx->create_socket (type_); return (void *) s; } @@ -325,7 +325,7 @@ static inline int s_sendmsg (zmq::socket_base_t *s_, zmq_msg_t *msg_, int flags_) { size_t sz = zmq_msg_size (msg_); - int rc = s_->send ((zmq::msg_t *) msg_, flags_); + int rc = s_->send (reinterpret_cast (msg_), flags_); if (unlikely (rc < 0)) return -1; @@ -334,7 +334,7 @@ s_sendmsg (zmq::socket_base_t *s_, zmq_msg_t *msg_, int flags_) size_t max_msgsz = INT_MAX; // Truncate returned size to INT_MAX to avoid overflow to negative values - return (int) (sz < max_msgsz ? sz : max_msgsz); + return static_cast (sz < max_msgsz ? sz : max_msgsz); } /* To be deprecated once zmq_msg_send() is stable */ @@ -376,7 +376,8 @@ int zmq_send_const (void *s_, const void *buf_, size_t len_, int flags_) if (!s) return -1; zmq_msg_t msg; - int rc = zmq_msg_init_data (&msg, (void *) buf_, len_, NULL, NULL); + int rc = + zmq_msg_init_data (&msg, const_cast (buf_), len_, NULL, NULL); if (rc != 0) return -1; @@ -440,13 +441,13 @@ int zmq_sendiov (void *s_, iovec *a_, size_t count_, int flags_) static int s_recvmsg (zmq::socket_base_t *s_, zmq_msg_t *msg_, int flags_) { - int rc = s_->recv ((zmq::msg_t *) msg_, flags_); + int rc = s_->recv (reinterpret_cast (msg_), flags_); if (unlikely (rc < 0)) return -1; // Truncate returned size to INT_MAX to avoid overflow to negative values size_t sz = zmq_msg_size (msg_); - return (int) (sz < INT_MAX ? sz : INT_MAX); + return static_cast (sz < INT_MAX ? sz : INT_MAX); } /* To be deprecated once zmq_msg_recv() is stable */ @@ -558,18 +559,19 @@ int zmq_recviov (void *s_, iovec *a_, size_t *count_, int flags_) int zmq_msg_init (zmq_msg_t *msg_) { - return ((zmq::msg_t *) msg_)->init (); + return (reinterpret_cast (msg_))->init (); } int zmq_msg_init_size (zmq_msg_t *msg_, size_t size_) { - return ((zmq::msg_t *) msg_)->init_size (size_); + return (reinterpret_cast (msg_))->init_size (size_); } int zmq_msg_init_data ( zmq_msg_t *msg_, void *data_, size_t size_, zmq_free_fn *ffn_, void *hint_) { - return ((zmq::msg_t *) msg_)->init_data (data_, size_, ffn_, hint_); + return (reinterpret_cast (msg_)) + ->init_data (data_, size_, ffn_, hint_); } int zmq_msg_send (zmq_msg_t *msg_, void *s_, int flags_) @@ -590,22 +592,24 @@ int zmq_msg_recv (zmq_msg_t *msg_, void *s_, int flags_) int zmq_msg_close (zmq_msg_t *msg_) { - return ((zmq::msg_t *) msg_)->close (); + return (reinterpret_cast (msg_))->close (); } int zmq_msg_move (zmq_msg_t *dest_, zmq_msg_t *src_) { - return ((zmq::msg_t *) dest_)->move (*(zmq::msg_t *) src_); + return (reinterpret_cast (dest_)) + ->move (*reinterpret_cast (src_)); } int zmq_msg_copy (zmq_msg_t *dest_, zmq_msg_t *src_) { - return ((zmq::msg_t *) dest_)->copy (*(zmq::msg_t *) src_); + return (reinterpret_cast (dest_)) + ->copy (*reinterpret_cast (src_)); } void *zmq_msg_data (zmq_msg_t *msg_) { - return ((zmq::msg_t *) msg_)->data (); + return (reinterpret_cast (msg_))->data (); } size_t zmq_msg_size (const zmq_msg_t *msg_) @@ -628,7 +632,7 @@ int zmq_msg_get (const zmq_msg_t *msg_, int property_) case ZMQ_SRCFD: fd_string = zmq_msg_gets (msg_, "__fd"); if (fd_string == NULL) - return (int) -1; + return -1; return atoi (fd_string); case ZMQ_SHARED: @@ -651,22 +655,23 @@ int zmq_msg_set (zmq_msg_t *, int, int) int zmq_msg_set_routing_id (zmq_msg_t *msg_, uint32_t routing_id_) { - return ((zmq::msg_t *) msg_)->set_routing_id (routing_id_); + return (reinterpret_cast (msg_)) + ->set_routing_id (routing_id_); } uint32_t zmq_msg_routing_id (zmq_msg_t *msg_) { - return ((zmq::msg_t *) msg_)->get_routing_id (); + return (reinterpret_cast (msg_))->get_routing_id (); } int zmq_msg_set_group (zmq_msg_t *msg_, const char *group_) { - return ((zmq::msg_t *) msg_)->set_group (group_); + return (reinterpret_cast (msg_))->set_group (group_); } const char *zmq_msg_group (zmq_msg_t *msg_) { - return ((zmq::msg_t *) msg_)->group (); + return (reinterpret_cast (msg_))->group (); } // Get message metadata string @@ -1043,8 +1048,8 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) } else if (timeout_ < 0) ptimeout = NULL; else { - timeout.tv_sec = (long) ((end - now) / 1000); - timeout.tv_usec = (long) ((end - now) % 1000 * 1000); + timeout.tv_sec = static_cast ((end - now) / 1000); + timeout.tv_usec = static_cast ((end - now) % 1000 * 1000); ptimeout = &timeout; } @@ -1056,14 +1061,17 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) // We just need to copy fd_count elements of fd_array. // We gain huge memcpy() improvement if number of used SOCKETs is much lower than FD_SETSIZE. memcpy (&inset, &pollset_in, - (char *) (pollset_in.fd_array + pollset_in.fd_count) - - (char *) &pollset_in); + reinterpret_cast (pollset_in.fd_array + + pollset_in.fd_count) + - reinterpret_cast (&pollset_in)); memcpy (&outset, &pollset_out, - (char *) (pollset_out.fd_array + pollset_out.fd_count) - - (char *) &pollset_out); + reinterpret_cast (pollset_out.fd_array + + pollset_out.fd_count) + - reinterpret_cast (&pollset_out)); memcpy (&errset, &pollset_err, - (char *) (pollset_err.fd_array + pollset_err.fd_count) - - (char *) &pollset_err); + reinterpret_cast (pollset_err.fd_array + + pollset_err.fd_count) + - reinterpret_cast (&pollset_err)); int rc = select (0, &inset, &outset, &errset, ptimeout); if (unlikely (rc == SOCKET_ERROR)) { errno = zmq::wsa_error_to_errno (WSAGetLastError ()); @@ -1176,21 +1184,24 @@ void *zmq_poller_new (void) int zmq_poller_destroy (void **poller_p_) { - void *poller; - if (!poller_p_ || !(poller = *poller_p_) - || !((zmq::socket_poller_t *) poller)->check_tag ()) { - errno = EFAULT; - return -1; + if (poller_p_) { + zmq::socket_poller_t *const poller = + static_cast (*poller_p_); + if (poller && poller->check_tag ()) { + delete poller; + *poller_p_ = NULL; + return 0; + } } - - delete ((zmq::socket_poller_t *) poller); - *poller_p_ = NULL; - return 0; + errno = EFAULT; + return -1; } + static int check_poller (void *const poller_) { - if (!poller_ || !((zmq::socket_poller_t *) poller_)->check_tag ()) { + if (!poller_ + || !(static_cast (poller_))->check_tag ()) { errno = EFAULT; return -1; } @@ -1212,7 +1223,7 @@ static int check_poller_registration_args (void *const poller_, void *const s_) if (-1 == check_poller (poller_)) return -1; - if (!s_ || !((zmq::socket_base_t *) s_)->check_tag ()) { + if (!s_ || !(static_cast (s_))->check_tag ()) { errno = ENOTSOCK; return -1; } @@ -1240,9 +1251,9 @@ int zmq_poller_add (void *poller_, void *s_, void *user_data_, short events_) || -1 == check_events (events_)) return -1; - zmq::socket_base_t *socket = (zmq::socket_base_t *) s_; + zmq::socket_base_t *socket = static_cast (s_); - return ((zmq::socket_poller_t *) poller_) + return (static_cast (poller_)) ->add (socket, user_data_, events_); } @@ -1255,7 +1266,7 @@ int zmq_poller_add_fd (void *poller_, || -1 == check_events (events_)) return -1; - return ((zmq::socket_poller_t *) poller_) + return (static_cast (poller_)) ->add_fd (fd_, user_data_, events_); } @@ -1266,9 +1277,10 @@ int zmq_poller_modify (void *poller_, void *s_, short events_) || -1 == check_events (events_)) return -1; - zmq::socket_base_t *socket = (zmq::socket_base_t *) s_; + zmq::socket_base_t *socket = static_cast (s_); - return ((zmq::socket_poller_t *) poller_)->modify (socket, events_); + return (static_cast (poller_)) + ->modify (socket, events_); } int zmq_poller_modify_fd (void *poller_, zmq::fd_t fd_, short events_) @@ -1277,7 +1289,8 @@ int zmq_poller_modify_fd (void *poller_, zmq::fd_t fd_, short events_) || -1 == check_events (events_)) return -1; - return ((zmq::socket_poller_t *) poller_)->modify_fd (fd_, events_); + return (static_cast (poller_)) + ->modify_fd (fd_, events_); } int zmq_poller_remove (void *poller_, void *s_) @@ -1285,9 +1298,9 @@ int zmq_poller_remove (void *poller_, void *s_) if (-1 == check_poller_registration_args (poller_, s_)) return -1; - zmq::socket_base_t *socket = (zmq::socket_base_t *) s_; + zmq::socket_base_t *socket = static_cast (s_); - return ((zmq::socket_poller_t *) poller_)->remove (socket); + return (static_cast (poller_))->remove (socket); } int zmq_poller_remove_fd (void *poller_, zmq::fd_t fd_) @@ -1295,7 +1308,7 @@ int zmq_poller_remove_fd (void *poller_, zmq::fd_t fd_) if (-1 == check_poller_fd_registration_args (poller_, fd_)) return -1; - return ((zmq::socket_poller_t *) poller_)->remove_fd (fd_); + return (static_cast (poller_))->remove_fd (fd_); } int zmq_poller_wait (void *poller_, zmq_poller_event_t *event_, long timeout_) @@ -1329,8 +1342,9 @@ int zmq_poller_wait_all (void *poller_, } int rc = - ((zmq::socket_poller_t *) poller_) - ->wait ((zmq::socket_poller_t::event_t *) events_, n_events, timeout_); + (static_cast (poller_)) + ->wait (reinterpret_cast (events_), + n_events, timeout_); return rc; } @@ -1360,11 +1374,11 @@ void *zmq_timers_new (void) int zmq_timers_destroy (void **timers_p_) { void *timers = *timers_p_; - if (!timers || !((zmq::timers_t *) timers)->check_tag ()) { + if (!timers || !(static_cast (timers))->check_tag ()) { errno = EFAULT; return -1; } - delete ((zmq::timers_t *) timers); + delete (static_cast (timers)); *timers_p_ = NULL; return 0; } @@ -1374,62 +1388,64 @@ int zmq_timers_add (void *timers_, zmq_timer_fn handler_, void *arg_) { - if (!timers_ || !((zmq::timers_t *) timers_)->check_tag ()) { + if (!timers_ || !(static_cast (timers_))->check_tag ()) { errno = EFAULT; return -1; } - return ((zmq::timers_t *) timers_)->add (interval_, handler_, arg_); + return (static_cast (timers_)) + ->add (interval_, handler_, arg_); } int zmq_timers_cancel (void *timers_, int timer_id_) { - if (!timers_ || !((zmq::timers_t *) timers_)->check_tag ()) { + if (!timers_ || !(static_cast (timers_))->check_tag ()) { errno = EFAULT; return -1; } - return ((zmq::timers_t *) timers_)->cancel (timer_id_); + return (static_cast (timers_))->cancel (timer_id_); } int zmq_timers_set_interval (void *timers_, int timer_id_, size_t interval_) { - if (!timers_ || !((zmq::timers_t *) timers_)->check_tag ()) { + if (!timers_ || !(static_cast (timers_))->check_tag ()) { errno = EFAULT; return -1; } - return ((zmq::timers_t *) timers_)->set_interval (timer_id_, interval_); + return (static_cast (timers_)) + ->set_interval (timer_id_, interval_); } int zmq_timers_reset (void *timers_, int timer_id_) { - if (!timers_ || !((zmq::timers_t *) timers_)->check_tag ()) { + if (!timers_ || !(static_cast (timers_))->check_tag ()) { errno = EFAULT; return -1; } - return ((zmq::timers_t *) timers_)->reset (timer_id_); + return (static_cast (timers_))->reset (timer_id_); } long zmq_timers_timeout (void *timers_) { - if (!timers_ || !((zmq::timers_t *) timers_)->check_tag ()) { + if (!timers_ || !(static_cast (timers_))->check_tag ()) { errno = EFAULT; return -1; } - return ((zmq::timers_t *) timers_)->timeout (); + return (static_cast (timers_))->timeout (); } int zmq_timers_execute (void *timers_) { - if (!timers_ || !((zmq::timers_t *) timers_)->check_tag ()) { + if (!timers_ || !(static_cast (timers_))->check_tag ()) { errno = EFAULT; return -1; } - return ((zmq::timers_t *) timers_)->execute (); + return (static_cast (timers_))->execute (); } // The proxy functionality @@ -1440,9 +1456,9 @@ int zmq_proxy (void *frontend_, void *backend_, void *capture_) errno = EFAULT; return -1; } - return zmq::proxy ((zmq::socket_base_t *) frontend_, - (zmq::socket_base_t *) backend_, - (zmq::socket_base_t *) capture_); + return zmq::proxy (static_cast (frontend_), + static_cast (backend_), + static_cast (capture_)); } int zmq_proxy_steerable (void *frontend_, @@ -1454,17 +1470,18 @@ int zmq_proxy_steerable (void *frontend_, errno = EFAULT; return -1; } - return zmq::proxy ( - (zmq::socket_base_t *) frontend_, (zmq::socket_base_t *) backend_, - (zmq::socket_base_t *) capture_, (zmq::socket_base_t *) control_); + return zmq::proxy (static_cast (frontend_), + static_cast (backend_), + static_cast (capture_), + static_cast (control_)); } // The deprecated device functionality int zmq_device (int /* type */, void *frontend_, void *backend_) { - return zmq::proxy ((zmq::socket_base_t *) frontend_, - (zmq::socket_base_t *) backend_, NULL); + return zmq::proxy (static_cast (frontend_), + static_cast (backend_), NULL); } // Probe library capabilities; for now, reports on transport and security diff --git a/src/zmq_utils.cpp b/src/zmq_utils.cpp index d07fc9245d..c9f69b81ce 100644 --- a/src/zmq_utils.cpp +++ b/src/zmq_utils.cpp @@ -60,7 +60,7 @@ void zmq_sleep (int seconds_) void *zmq_stopwatch_start () { - uint64_t *watch = (uint64_t *) malloc (sizeof (uint64_t)); + uint64_t *watch = static_cast (malloc (sizeof (uint64_t))); alloc_assert (watch); *watch = zmq::clock_t::now_us (); return (void *) watch; @@ -69,8 +69,8 @@ void *zmq_stopwatch_start () unsigned long zmq_stopwatch_intermediate (void *watch_) { uint64_t end = zmq::clock_t::now_us (); - uint64_t start = *(uint64_t *) watch_; - return (unsigned long) (end - start); + uint64_t start = *static_cast (watch_); + return static_cast (end - start); } unsigned long zmq_stopwatch_stop (void *watch_) @@ -287,14 +287,14 @@ void *zmq_atomic_counter_new (void) void zmq_atomic_counter_set (void *counter_, int value_) { - ((zmq::atomic_counter_t *) counter_)->set (value_); + (static_cast (counter_))->set (value_); } // Increment the atomic counter, and return the old value int zmq_atomic_counter_inc (void *counter_) { - return ((zmq::atomic_counter_t *) counter_)->add (1); + return (static_cast (counter_))->add (1); } // Decrement the atomic counter and return 1 (if counter >= 1), or @@ -302,20 +302,20 @@ int zmq_atomic_counter_inc (void *counter_) int zmq_atomic_counter_dec (void *counter_) { - return ((zmq::atomic_counter_t *) counter_)->sub (1) ? 1 : 0; + return (static_cast (counter_))->sub (1) ? 1 : 0; } // Return actual value of atomic counter int zmq_atomic_counter_value (void *counter_) { - return ((zmq::atomic_counter_t *) counter_)->get (); + return (static_cast (counter_))->get (); } // Destroy atomic counter, and set reference to NULL void zmq_atomic_counter_destroy (void **counter_p_) { - delete ((zmq::atomic_counter_t *) *counter_p_); + delete (static_cast (*counter_p_)); *counter_p_ = NULL; }