Commit 12a97bb7 authored by Simon Giesecke's avatar Simon Giesecke

Problem: redundant else after return

Solution: remove else
parent 21498700
...@@ -125,7 +125,7 @@ zmq::mechanism_t::status_t zmq::curve_client_t::status () const ...@@ -125,7 +125,7 @@ zmq::mechanism_t::status_t zmq::curve_client_t::status () const
{ {
if (state == connected) if (state == connected)
return mechanism_t::ready; return mechanism_t::ready;
else if (state == error_received) if (state == error_received)
return mechanism_t::error; return mechanism_t::error;
else else
return mechanism_t::handshaking; return mechanism_t::handshaking;
......
...@@ -288,35 +288,34 @@ int zmq::dish_session_t::push_msg (msg_t *msg_) ...@@ -288,35 +288,34 @@ int zmq::dish_session_t::push_msg (msg_t *msg_)
int rc = msg_->init (); int rc = msg_->init ();
errno_assert (rc == 0); errno_assert (rc == 0);
return 0; return 0;
} else { }
const char *group_setting = msg_->group (); const char *group_setting = msg_->group ();
int rc; int rc;
if (group_setting[0] != 0) if (group_setting[0] != 0)
goto has_group; goto has_group;
// Set the message group // Set the message group
rc = msg_->set_group (static_cast<char *> (group_msg.data ()), rc = msg_->set_group (static_cast<char *> (group_msg.data ()),
group_msg.size ()); group_msg.size ());
errno_assert (rc == 0); errno_assert (rc == 0);
// We set the group, so we don't need the group_msg anymore // We set the group, so we don't need the group_msg anymore
rc = group_msg.close (); rc = group_msg.close ();
errno_assert (rc == 0); errno_assert (rc == 0);
has_group: has_group:
// Thread safe socket doesn't support multipart messages // Thread safe socket doesn't support multipart messages
if ((msg_->flags () & msg_t::more) == msg_t::more) { if ((msg_->flags () & msg_t::more) == msg_t::more) {
errno = EFAULT; errno = EFAULT;
return -1; return -1;
} }
// Push message to dish socket // Push message to dish socket
rc = session_base_t::push_msg (msg_); rc = session_base_t::push_msg (msg_);
if (rc == 0) if (rc == 0)
state = group; state = group;
return rc; return rc;
}
} }
int zmq::dish_session_t::pull_msg (msg_t *msg_) int zmq::dish_session_t::pull_msg (msg_t *msg_)
...@@ -328,38 +327,37 @@ int zmq::dish_session_t::pull_msg (msg_t *msg_) ...@@ -328,38 +327,37 @@ int zmq::dish_session_t::pull_msg (msg_t *msg_)
if (!msg_->is_join () && !msg_->is_leave ()) if (!msg_->is_join () && !msg_->is_leave ())
return rc; return rc;
else {
int group_length = static_cast<int> (strlen (msg_->group ()));
msg_t command;
int offset;
if (msg_->is_join ()) {
rc = command.init_size (group_length + 5);
errno_assert (rc == 0);
offset = 5;
memcpy (command.data (), "\4JOIN", 5);
} else {
rc = command.init_size (group_length + 6);
errno_assert (rc == 0);
offset = 6;
memcpy (command.data (), "\5LEAVE", 6);
}
command.set_flags (msg_t::command); int group_length = static_cast<int> (strlen (msg_->group ()));
char *command_data = static_cast<char *> (command.data ());
// Copy the group msg_t command;
memcpy (command_data + offset, msg_->group (), group_length); int offset;
// Close the join message if (msg_->is_join ()) {
rc = msg_->close (); rc = command.init_size (group_length + 5);
errno_assert (rc == 0); errno_assert (rc == 0);
offset = 5;
memcpy (command.data (), "\4JOIN", 5);
} else {
rc = command.init_size (group_length + 6);
errno_assert (rc == 0);
offset = 6;
memcpy (command.data (), "\5LEAVE", 6);
}
*msg_ = command; command.set_flags (msg_t::command);
char *command_data = static_cast<char *> (command.data ());
return 0; // Copy the group
} memcpy (command_data + offset, msg_->group (), group_length);
// Close the join message
rc = msg_->close ();
errno_assert (rc == 0);
*msg_ = command;
return 0;
} }
void zmq::dish_session_t::reset () void zmq::dish_session_t::reset ()
......
...@@ -140,14 +140,13 @@ bool zmq::generic_mtrie_t<T>::add_helper (prefix_t prefix_, ...@@ -140,14 +140,13 @@ bool zmq::generic_mtrie_t<T>::add_helper (prefix_t prefix_,
++live_nodes; ++live_nodes;
} }
return next.node->add_helper (prefix_ + 1, size_ - 1, pipe_); return next.node->add_helper (prefix_ + 1, size_ - 1, pipe_);
} else {
if (!next.table[c - min]) {
next.table[c - min] = new (std::nothrow) generic_mtrie_t;
alloc_assert (next.table[c - min]);
++live_nodes;
}
return next.table[c - min]->add_helper (prefix_ + 1, size_ - 1, pipe_);
} }
if (!next.table[c - min]) {
next.table[c - min] = new (std::nothrow) generic_mtrie_t;
alloc_assert (next.table[c - min]);
++live_nodes;
}
return next.table[c - min]->add_helper (prefix_ + 1, size_ - 1, pipe_);
} }
......
...@@ -526,17 +526,17 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_) ...@@ -526,17 +526,17 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_)
if (*r_ != INVALID_SOCKET) { if (*r_ != INVALID_SOCKET) {
make_socket_noninheritable (*r_); make_socket_noninheritable (*r_);
return 0; return 0;
} else {
// Cleanup writer if connection failed
if (*w_ != INVALID_SOCKET) {
rc = closesocket (*w_);
wsa_assert (rc != SOCKET_ERROR);
*w_ = INVALID_SOCKET;
}
// Set errno from saved value
errno = wsa_error_to_errno (saved_errno);
return -1;
} }
// Cleanup writer if connection failed
if (*w_ != INVALID_SOCKET) {
rc = closesocket (*w_);
wsa_assert (rc != SOCKET_ERROR);
*w_ = INVALID_SOCKET;
}
// Set errno from saved value
errno = wsa_error_to_errno (saved_errno);
return -1;
#elif defined ZMQ_HAVE_OPENVMS #elif defined ZMQ_HAVE_OPENVMS
......
...@@ -31,19 +31,17 @@ bool zmq::ip_addr_t::is_multicast () const ...@@ -31,19 +31,17 @@ bool zmq::ip_addr_t::is_multicast () const
// IPv4 Multicast: address MSBs are 1110 // IPv4 Multicast: address MSBs are 1110
// Range: 224.0.0.0 - 239.255.255.255 // Range: 224.0.0.0 - 239.255.255.255
return IN_MULTICAST (ntohl (ipv4.sin_addr.s_addr)); return IN_MULTICAST (ntohl (ipv4.sin_addr.s_addr));
} else {
// IPv6 Multicast: ff00::/8
return IN6_IS_ADDR_MULTICAST (&ipv6.sin6_addr) != 0;
} }
// IPv6 Multicast: ff00::/8
return IN6_IS_ADDR_MULTICAST (&ipv6.sin6_addr) != 0;
} }
uint16_t zmq::ip_addr_t::port () const uint16_t zmq::ip_addr_t::port () const
{ {
if (family () == AF_INET6) { if (family () == AF_INET6) {
return ntohs (ipv6.sin6_port); return ntohs (ipv6.sin6_port);
} else {
return ntohs (ipv4.sin_port);
} }
return ntohs (ipv4.sin_port);
} }
const struct sockaddr *zmq::ip_addr_t::as_sockaddr () const const struct sockaddr *zmq::ip_addr_t::as_sockaddr () const
...@@ -55,9 +53,8 @@ socklen_t zmq::ip_addr_t::sockaddr_len () const ...@@ -55,9 +53,8 @@ socklen_t zmq::ip_addr_t::sockaddr_len () const
{ {
if (family () == AF_INET6) { if (family () == AF_INET6) {
return sizeof (ipv6); return sizeof (ipv6);
} else {
return sizeof (ipv4);
} }
return sizeof (ipv4);
} }
void zmq::ip_addr_t::set_port (uint16_t port_) void zmq::ip_addr_t::set_port (uint16_t port_)
......
...@@ -43,8 +43,8 @@ const char *zmq::metadata_t::get (const std::string &property_) const ...@@ -43,8 +43,8 @@ const char *zmq::metadata_t::get (const std::string &property_) const
return get (ZMQ_MSG_PROPERTY_ROUTING_ID); return get (ZMQ_MSG_PROPERTY_ROUTING_ID);
return NULL; return NULL;
} else }
return it->second.c_str (); return it->second.c_str ();
} }
void zmq::metadata_t::add_ref () void zmq::metadata_t::add_ref ()
......
...@@ -64,9 +64,9 @@ int zmq::msg_t::init (void *data_, ...@@ -64,9 +64,9 @@ int zmq::msg_t::init (void *data_,
if (rc != -1) { if (rc != -1) {
memcpy (data (), data_, size_); memcpy (data (), data_, size_);
return 0; return 0;
} else {
return -1;
} }
return -1;
} else if (content_) { } else if (content_) {
return init_external_storage (content_, data_, size_, ffn_, hint_); return init_external_storage (content_, data_, size_, ffn_, hint_);
} else { } else {
......
...@@ -75,7 +75,8 @@ int zmq::null_mechanism_t::next_handshake_command (msg_t *msg_) ...@@ -75,7 +75,8 @@ int zmq::null_mechanism_t::next_handshake_command (msg_t *msg_)
session->get_socket ()->event_handshake_failed_no_detail ( session->get_socket ()->event_handshake_failed_no_detail (
session->get_endpoint (), EFAULT); session->get_endpoint (), EFAULT);
return -1; return -1;
} else if (rc == 0) { }
if (rc == 0) {
send_zap_request (); send_zap_request ();
zap_request_sent = true; zap_request_sent = true;
...@@ -103,10 +104,9 @@ int zmq::null_mechanism_t::next_handshake_command (msg_t *msg_) ...@@ -103,10 +104,9 @@ int zmq::null_mechanism_t::next_handshake_command (msg_t *msg_)
msg_data[6] = status_code_len; msg_data[6] = status_code_len;
memcpy (msg_data + 7, status_code.c_str (), status_code_len); memcpy (msg_data + 7, status_code.c_str (), status_code_len);
return 0; return 0;
} else {
errno = EAGAIN;
return -1;
} }
errno = EAGAIN;
return -1;
} }
make_command_with_basic_properties (msg_, "\5READY", 6); make_command_with_basic_properties (msg_, "\5READY", 6);
...@@ -203,7 +203,7 @@ zmq::mechanism_t::status_t zmq::null_mechanism_t::status () const ...@@ -203,7 +203,7 @@ zmq::mechanism_t::status_t zmq::null_mechanism_t::status () const
if (ready_command_sent && ready_command_received) if (ready_command_sent && ready_command_received)
return mechanism_t::ready; return mechanism_t::ready;
else if (command_sent && command_received) if (command_sent && command_received)
return error; return error;
else else
return handshaking; return handshaking;
......
...@@ -90,7 +90,8 @@ static int do_getsockopt_curve_key (void *const optval_, ...@@ -90,7 +90,8 @@ static int do_getsockopt_curve_key (void *const optval_,
if (*optvallen_ == CURVE_KEYSIZE) { if (*optvallen_ == CURVE_KEYSIZE) {
memcpy (optval_, curve_key_, CURVE_KEYSIZE); memcpy (optval_, curve_key_, CURVE_KEYSIZE);
return 0; return 0;
} else if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) { }
if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
zmq_z85_encode (static_cast<char *> (optval_), curve_key_, zmq_z85_encode (static_cast<char *> (optval_), curve_key_,
CURVE_KEYSIZE); CURVE_KEYSIZE);
return 0; return 0;
...@@ -150,7 +151,8 @@ do_setsockopt_string_allow_empty_strict (const void *const optval_, ...@@ -150,7 +151,8 @@ do_setsockopt_string_allow_empty_strict (const void *const optval_,
if (optval_ == NULL && optvallen_ == 0) { if (optval_ == NULL && optvallen_ == 0) {
out_value_->clear (); out_value_->clear ();
return 0; return 0;
} else if (optval_ != NULL && optvallen_ > 0 && optvallen_ <= max_len_) { }
if (optval_ != NULL && optvallen_ > 0 && optvallen_ <= max_len_) {
out_value_->assign (static_cast<const char *> (optval_), optvallen_); out_value_->assign (static_cast<const char *> (optval_), optvallen_);
return 0; return 0;
} }
......
...@@ -404,7 +404,7 @@ void zmq::pipe_t::terminate (bool delay_) ...@@ -404,7 +404,7 @@ void zmq::pipe_t::terminate (bool delay_)
} }
// If the pipe is in the final phase of async termination, it's going to // If the pipe is in the final phase of async termination, it's going to
// closed anyway. No need to do anything special here. // closed anyway. No need to do anything special here.
else if (state == term_ack_sent) { if (state == term_ack_sent) {
return; return;
} }
// The simple sync termination case. Ask the peer to terminate and wait // The simple sync termination case. Ask the peer to terminate and wait
......
...@@ -104,7 +104,7 @@ zmq::mechanism_t::status_t zmq::plain_client_t::status () const ...@@ -104,7 +104,7 @@ zmq::mechanism_t::status_t zmq::plain_client_t::status () const
{ {
if (state == ready) if (state == ready)
return mechanism_t::ready; return mechanism_t::ready;
else if (state == error_command_received) if (state == error_command_received)
return mechanism_t::error; return mechanism_t::error;
else else
return mechanism_t::handshaking; return mechanism_t::handshaking;
......
...@@ -240,8 +240,8 @@ int zmq::radio_session_t::push_msg (msg_t *msg_) ...@@ -240,8 +240,8 @@ int zmq::radio_session_t::push_msg (msg_t *msg_)
// Push the join or leave command // Push the join or leave command
*msg_ = join_leave_msg; *msg_ = join_leave_msg;
return session_base_t::push_msg (msg_); return session_base_t::push_msg (msg_);
} else }
return session_base_t::push_msg (msg_); return session_base_t::push_msg (msg_);
} }
int zmq::radio_session_t::pull_msg (msg_t *msg_) int zmq::radio_session_t::pull_msg (msg_t *msg_)
...@@ -263,11 +263,10 @@ int zmq::radio_session_t::pull_msg (msg_t *msg_) ...@@ -263,11 +263,10 @@ int zmq::radio_session_t::pull_msg (msg_t *msg_)
// Next status is the body // Next status is the body
state = body; state = body;
return 0; return 0;
} else {
*msg_ = pending_msg;
state = group;
return 0;
} }
*msg_ = pending_msg;
state = group;
return 0;
} }
void zmq::radio_session_t::reset () void zmq::radio_session_t::reset ()
......
...@@ -507,35 +507,33 @@ bool zmq::router_t::identify_peer (pipe_t *pipe_) ...@@ -507,35 +507,33 @@ bool zmq::router_t::identify_peer (pipe_t *pipe_)
if (!handover) if (!handover)
// Ignore peers with duplicate ID // Ignore peers with duplicate ID
return false; return false;
else {
// We will allow the new connection to take over this // We will allow the new connection to take over this
// routing id. Temporarily assign a new routing id to the // routing id. Temporarily assign a new routing id to the
// existing pipe so we can terminate it asynchronously. // existing pipe so we can terminate it asynchronously.
unsigned char buf[5]; unsigned char buf[5];
buf[0] = 0; buf[0] = 0;
put_uint32 (buf + 1, next_integral_routing_id++); put_uint32 (buf + 1, next_integral_routing_id++);
blob_t new_routing_id (buf, sizeof buf); blob_t new_routing_id (buf, sizeof buf);
it->second.pipe->set_router_socket_routing_id ( it->second.pipe->set_router_socket_routing_id (new_routing_id);
new_routing_id); outpipe_t existing_outpipe = {it->second.pipe,
outpipe_t existing_outpipe = {it->second.pipe, it->second.active};
it->second.active};
ok = outpipes
ok = outpipes .ZMQ_MAP_INSERT_OR_EMPLACE (ZMQ_MOVE (new_routing_id),
.ZMQ_MAP_INSERT_OR_EMPLACE ( existing_outpipe)
ZMQ_MOVE (new_routing_id), existing_outpipe) .second;
.second; zmq_assert (ok);
zmq_assert (ok);
// Remove the existing routing id entry to allow the new
// Remove the existing routing id entry to allow the new // connection to take the routing id.
// connection to take the routing id. outpipes.erase (it);
outpipes.erase (it);
if (existing_outpipe.pipe == current_in)
if (existing_outpipe.pipe == current_in) terminate_current_in = true;
terminate_current_in = true; else
else existing_outpipe.pipe->terminate (true);
existing_outpipe.pipe->terminate (true);
}
} }
} }
} }
......
...@@ -583,15 +583,14 @@ u_short zmq::select_t::determine_fd_family (fd_t fd_) ...@@ -583,15 +583,14 @@ u_short zmq::select_t::determine_fd_family (fd_t fd_)
if (rc == 0) { if (rc == 0) {
if (type == SOCK_DGRAM) if (type == SOCK_DGRAM)
return AF_INET; return AF_INET;
else {
rc = getsockname (fd_, reinterpret_cast<sockaddr *> (&addr), rc =
&addr_size); getsockname (fd_, reinterpret_cast<sockaddr *> (&addr), &addr_size);
// AF_INET and AF_INET6 can be mixed in select // AF_INET and AF_INET6 can be mixed in select
// TODO: If proven otherwise, should simply return addr.sa_family // TODO: If proven otherwise, should simply return addr.sa_family
if (rc != SOCKET_ERROR) if (rc != SOCKET_ERROR)
return addr.ss_family == AF_INET6 ? AF_INET : addr.ss_family; return addr.ss_family == AF_INET6 ? AF_INET : addr.ss_family;
}
} }
return AF_UNSPEC; return AF_UNSPEC;
......
...@@ -266,16 +266,15 @@ bool zmq::socks_response_decoder_t::message_ready () const ...@@ -266,16 +266,15 @@ bool zmq::socks_response_decoder_t::message_ready () const
{ {
if (bytes_read < 4) if (bytes_read < 4)
return false; return false;
else {
const uint8_t atyp = buf[3]; const uint8_t atyp = buf[3];
zmq_assert (atyp == 0x01 || atyp == 0x03 || atyp == 0x04); zmq_assert (atyp == 0x01 || atyp == 0x03 || atyp == 0x04);
if (atyp == 0x01) if (atyp == 0x01)
return bytes_read == 10; return bytes_read == 10;
else if (atyp == 0x03) if (atyp == 0x03)
return bytes_read > 4 && bytes_read == 4 + 1 + buf[4] + 2u; return bytes_read > 4 && bytes_read == 4 + 1 + buf[4] + 2u;
else else
return bytes_read == 22; return bytes_read == 22;
}
} }
zmq::socks_response_t zmq::socks_response_decoder_t::decode () zmq::socks_response_t zmq::socks_response_decoder_t::decode ()
......
...@@ -770,7 +770,8 @@ int zmq::stream_engine_t::next_handshake_command (msg_t *msg_) ...@@ -770,7 +770,8 @@ int zmq::stream_engine_t::next_handshake_command (msg_t *msg_)
if (mechanism->status () == mechanism_t::ready) { if (mechanism->status () == mechanism_t::ready) {
mechanism_ready (); mechanism_ready ();
return pull_and_encode (msg_); return pull_and_encode (msg_);
} else if (mechanism->status () == mechanism_t::error) { }
if (mechanism->status () == mechanism_t::error) {
errno = EPROTO; errno = EPROTO;
return -1; return -1;
} else { } else {
......
...@@ -153,8 +153,8 @@ socklen_t zmq::tcp_address_t::addrlen () const ...@@ -153,8 +153,8 @@ socklen_t zmq::tcp_address_t::addrlen () const
{ {
if (address.generic.sa_family == AF_INET6) if (address.generic.sa_family == AF_INET6)
return static_cast<socklen_t> (sizeof (address.ipv6)); return static_cast<socklen_t> (sizeof (address.ipv6));
else
return static_cast<socklen_t> (sizeof (address.ipv4)); return static_cast<socklen_t> (sizeof (address.ipv4));
} }
const sockaddr *zmq::tcp_address_t::src_addr () const const sockaddr *zmq::tcp_address_t::src_addr () const
...@@ -166,8 +166,8 @@ socklen_t zmq::tcp_address_t::src_addrlen () const ...@@ -166,8 +166,8 @@ socklen_t zmq::tcp_address_t::src_addrlen () const
{ {
if (address.family () == AF_INET6) if (address.family () == AF_INET6)
return static_cast<socklen_t> (sizeof (source_address.ipv6)); return static_cast<socklen_t> (sizeof (source_address.ipv6));
else
return static_cast<socklen_t> (sizeof (source_address.ipv4)); return static_cast<socklen_t> (sizeof (source_address.ipv4));
} }
bool zmq::tcp_address_t::has_src_addr () const bool zmq::tcp_address_t::has_src_addr () const
......
...@@ -147,8 +147,8 @@ long zmq::timers_t::timeout () ...@@ -147,8 +147,8 @@ long zmq::timers_t::timeout ()
if (cancelled_it == cancelled_timers.end ()) { if (cancelled_it == cancelled_timers.end ()) {
if (it->first > now) if (it->first > now)
return static_cast<long> (it->first - now); return static_cast<long> (it->first - now);
else
return 0; return 0;
} }
// Let's remove it from the beginning of the list // Let's remove it from the beginning of the list
......
...@@ -114,15 +114,14 @@ bool zmq::trie_t::add (unsigned char *prefix_, size_t size_) ...@@ -114,15 +114,14 @@ bool zmq::trie_t::add (unsigned char *prefix_, size_t size_)
zmq_assert (live_nodes == 1); zmq_assert (live_nodes == 1);
} }
return next.node->add (prefix_ + 1, size_ - 1); return next.node->add (prefix_ + 1, size_ - 1);
} else {
if (!next.table[c - min]) {
next.table[c - min] = new (std::nothrow) trie_t;
alloc_assert (next.table[c - min]);
++live_nodes;
zmq_assert (live_nodes > 1);
}
return next.table[c - min]->add (prefix_ + 1, size_ - 1);
} }
if (!next.table[c - min]) {
next.table[c - min] = new (std::nothrow) trie_t;
alloc_assert (next.table[c - min]);
++live_nodes;
zmq_assert (live_nodes > 1);
}
return next.table[c - min]->add (prefix_ + 1, size_ - 1);
} }
bool zmq::trie_t::rm (unsigned char *prefix_, size_t size_) bool zmq::trie_t::rm (unsigned char *prefix_, size_t size_)
......
...@@ -104,7 +104,8 @@ int zmq::xsub_t::xsend (msg_t *msg_) ...@@ -104,7 +104,8 @@ int zmq::xsub_t::xsend (msg_t *msg_)
// when there are forwarding devices involved. // when there are forwarding devices involved.
subscriptions.add (data + 1, size - 1); subscriptions.add (data + 1, size - 1);
return dist.send_to_all (msg_); return dist.send_to_all (msg_);
} else if (size > 0 && *data == 0) { }
if (size > 0 && *data == 0) {
// Process unsubscribe message // Process unsubscribe message
if (subscriptions.rm (data + 1, size - 1)) if (subscriptions.rm (data + 1, size - 1))
return dist.send_to_all (msg_); return dist.send_to_all (msg_);
......
...@@ -263,7 +263,7 @@ zmq::mechanism_t::status_t zap_client_common_handshake_t::status () const ...@@ -263,7 +263,7 @@ zmq::mechanism_t::status_t zap_client_common_handshake_t::status () const
{ {
if (state == ready) if (state == ready)
return mechanism_t::ready; return mechanism_t::ready;
else if (state == error_sent) if (state == error_sent)
return mechanism_t::error; return mechanism_t::error;
else else
return mechanism_t::handshaking; return mechanism_t::handshaking;
......
...@@ -685,10 +685,9 @@ const char *zmq_msg_gets (const zmq_msg_t *msg_, const char *property_) ...@@ -685,10 +685,9 @@ const char *zmq_msg_gets (const zmq_msg_t *msg_, const char *property_)
value = metadata->get (std::string (property_)); value = metadata->get (std::string (property_));
if (value) if (value)
return value; return value;
else {
errno = EINVAL; errno = EINVAL;
return NULL; return NULL;
}
} }
// Polling. // Polling.
......
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