Problem: redundant else after return

Solution: remove else
This commit is contained in:
Simon Giesecke 2018-05-25 23:10:10 +02:00
parent 21498700ef
commit 12a97bb769
22 changed files with 154 additions and 163 deletions

View File

@ -125,7 +125,7 @@ zmq::mechanism_t::status_t zmq::curve_client_t::status () const
{
if (state == connected)
return mechanism_t::ready;
else if (state == error_received)
if (state == error_received)
return mechanism_t::error;
else
return mechanism_t::handshaking;

View File

@ -288,35 +288,34 @@ int zmq::dish_session_t::push_msg (msg_t *msg_)
int rc = msg_->init ();
errno_assert (rc == 0);
return 0;
} else {
const char *group_setting = msg_->group ();
int rc;
if (group_setting[0] != 0)
goto has_group;
// Set the message group
rc = msg_->set_group (static_cast<char *> (group_msg.data ()),
group_msg.size ());
errno_assert (rc == 0);
// We set the group, so we don't need the group_msg anymore
rc = group_msg.close ();
errno_assert (rc == 0);
has_group:
// Thread safe socket doesn't support multipart messages
if ((msg_->flags () & msg_t::more) == msg_t::more) {
errno = EFAULT;
return -1;
}
// Push message to dish socket
rc = session_base_t::push_msg (msg_);
if (rc == 0)
state = group;
return rc;
}
const char *group_setting = msg_->group ();
int rc;
if (group_setting[0] != 0)
goto has_group;
// Set the message group
rc = msg_->set_group (static_cast<char *> (group_msg.data ()),
group_msg.size ());
errno_assert (rc == 0);
// We set the group, so we don't need the group_msg anymore
rc = group_msg.close ();
errno_assert (rc == 0);
has_group:
// Thread safe socket doesn't support multipart messages
if ((msg_->flags () & msg_t::more) == msg_t::more) {
errno = EFAULT;
return -1;
}
// Push message to dish socket
rc = session_base_t::push_msg (msg_);
if (rc == 0)
state = group;
return rc;
}
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 ())
return rc;
else {
int group_length = static_cast<int> (strlen (msg_->group ()));
msg_t command;
int offset;
int group_length = static_cast<int> (strlen (msg_->group ()));
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);
}
msg_t command;
int offset;
command.set_flags (msg_t::command);
char *command_data = static_cast<char *> (command.data ());
// Copy the group
memcpy (command_data + offset, msg_->group (), group_length);
// Close the join message
rc = msg_->close ();
if (msg_->is_join ()) {
rc = command.init_size (group_length + 5);
errno_assert (rc == 0);
*msg_ = command;
return 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);
char *command_data = static_cast<char *> (command.data ());
// 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 ()

View File

@ -140,14 +140,13 @@ bool zmq::generic_mtrie_t<T>::add_helper (prefix_t prefix_,
++live_nodes;
}
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_);
}

View File

@ -526,17 +526,17 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_)
if (*r_ != INVALID_SOCKET) {
make_socket_noninheritable (*r_);
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

View File

@ -31,19 +31,17 @@ bool zmq::ip_addr_t::is_multicast () const
// IPv4 Multicast: address MSBs are 1110
// Range: 224.0.0.0 - 239.255.255.255
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
{
if (family () == AF_INET6) {
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
@ -55,9 +53,8 @@ socklen_t zmq::ip_addr_t::sockaddr_len () const
{
if (family () == AF_INET6) {
return sizeof (ipv6);
} else {
return sizeof (ipv4);
}
return sizeof (ipv4);
}
void zmq::ip_addr_t::set_port (uint16_t port_)

View File

@ -43,8 +43,8 @@ const char *zmq::metadata_t::get (const std::string &property_) const
return get (ZMQ_MSG_PROPERTY_ROUTING_ID);
return NULL;
} else
return it->second.c_str ();
}
return it->second.c_str ();
}
void zmq::metadata_t::add_ref ()

View File

@ -64,9 +64,9 @@ int zmq::msg_t::init (void *data_,
if (rc != -1) {
memcpy (data (), data_, size_);
return 0;
} else {
return -1;
}
return -1;
} else if (content_) {
return init_external_storage (content_, data_, size_, ffn_, hint_);
} else {

View File

@ -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_endpoint (), EFAULT);
return -1;
} else if (rc == 0) {
}
if (rc == 0) {
send_zap_request ();
zap_request_sent = true;
@ -103,10 +104,9 @@ int zmq::null_mechanism_t::next_handshake_command (msg_t *msg_)
msg_data[6] = status_code_len;
memcpy (msg_data + 7, status_code.c_str (), status_code_len);
return 0;
} else {
errno = EAGAIN;
return -1;
}
errno = EAGAIN;
return -1;
}
make_command_with_basic_properties (msg_, "\5READY", 6);
@ -203,7 +203,7 @@ zmq::mechanism_t::status_t zmq::null_mechanism_t::status () const
if (ready_command_sent && ready_command_received)
return mechanism_t::ready;
else if (command_sent && command_received)
if (command_sent && command_received)
return error;
else
return handshaking;

View File

@ -90,7 +90,8 @@ static int do_getsockopt_curve_key (void *const optval_,
if (*optvallen_ == CURVE_KEYSIZE) {
memcpy (optval_, curve_key_, CURVE_KEYSIZE);
return 0;
} else if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
}
if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
zmq_z85_encode (static_cast<char *> (optval_), curve_key_,
CURVE_KEYSIZE);
return 0;
@ -150,7 +151,8 @@ do_setsockopt_string_allow_empty_strict (const void *const optval_,
if (optval_ == NULL && optvallen_ == 0) {
out_value_->clear ();
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_);
return 0;
}

View File

@ -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
// closed anyway. No need to do anything special here.
else if (state == term_ack_sent) {
if (state == term_ack_sent) {
return;
}
// The simple sync termination case. Ask the peer to terminate and wait

View File

@ -104,7 +104,7 @@ zmq::mechanism_t::status_t zmq::plain_client_t::status () const
{
if (state == ready)
return mechanism_t::ready;
else if (state == error_command_received)
if (state == error_command_received)
return mechanism_t::error;
else
return mechanism_t::handshaking;

View File

@ -240,8 +240,8 @@ int zmq::radio_session_t::push_msg (msg_t *msg_)
// Push the join or leave command
*msg_ = join_leave_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_)
@ -263,11 +263,10 @@ int zmq::radio_session_t::pull_msg (msg_t *msg_)
// Next status is the body
state = body;
return 0;
} else {
*msg_ = pending_msg;
state = group;
return 0;
}
*msg_ = pending_msg;
state = group;
return 0;
}
void zmq::radio_session_t::reset ()

View File

@ -507,35 +507,33 @@ bool zmq::router_t::identify_peer (pipe_t *pipe_)
if (!handover)
// Ignore peers with duplicate ID
return false;
else {
// We will allow the new connection to take over this
// routing id. Temporarily assign a new routing id to the
// existing pipe so we can terminate it asynchronously.
unsigned char buf[5];
buf[0] = 0;
put_uint32 (buf + 1, next_integral_routing_id++);
blob_t new_routing_id (buf, sizeof buf);
it->second.pipe->set_router_socket_routing_id (
new_routing_id);
outpipe_t existing_outpipe = {it->second.pipe,
it->second.active};
// We will allow the new connection to take over this
// routing id. Temporarily assign a new routing id to the
// existing pipe so we can terminate it asynchronously.
unsigned char buf[5];
buf[0] = 0;
put_uint32 (buf + 1, next_integral_routing_id++);
blob_t new_routing_id (buf, sizeof buf);
ok = outpipes
.ZMQ_MAP_INSERT_OR_EMPLACE (
ZMQ_MOVE (new_routing_id), existing_outpipe)
.second;
zmq_assert (ok);
it->second.pipe->set_router_socket_routing_id (new_routing_id);
outpipe_t existing_outpipe = {it->second.pipe,
it->second.active};
// Remove the existing routing id entry to allow the new
// connection to take the routing id.
outpipes.erase (it);
ok = outpipes
.ZMQ_MAP_INSERT_OR_EMPLACE (ZMQ_MOVE (new_routing_id),
existing_outpipe)
.second;
zmq_assert (ok);
if (existing_outpipe.pipe == current_in)
terminate_current_in = true;
else
existing_outpipe.pipe->terminate (true);
}
// Remove the existing routing id entry to allow the new
// connection to take the routing id.
outpipes.erase (it);
if (existing_outpipe.pipe == current_in)
terminate_current_in = true;
else
existing_outpipe.pipe->terminate (true);
}
}
}

View File

@ -583,15 +583,14 @@ u_short zmq::select_t::determine_fd_family (fd_t fd_)
if (rc == 0) {
if (type == SOCK_DGRAM)
return AF_INET;
else {
rc = getsockname (fd_, reinterpret_cast<sockaddr *> (&addr),
&addr_size);
// AF_INET and AF_INET6 can be mixed in select
// TODO: If proven otherwise, should simply return addr.sa_family
if (rc != SOCKET_ERROR)
return addr.ss_family == AF_INET6 ? AF_INET : addr.ss_family;
}
rc =
getsockname (fd_, reinterpret_cast<sockaddr *> (&addr), &addr_size);
// AF_INET and AF_INET6 can be mixed in select
// TODO: If proven otherwise, should simply return addr.sa_family
if (rc != SOCKET_ERROR)
return addr.ss_family == AF_INET6 ? AF_INET : addr.ss_family;
}
return AF_UNSPEC;

View File

@ -266,16 +266,15 @@ bool zmq::socks_response_decoder_t::message_ready () const
{
if (bytes_read < 4)
return false;
else {
const uint8_t atyp = buf[3];
zmq_assert (atyp == 0x01 || atyp == 0x03 || atyp == 0x04);
if (atyp == 0x01)
return bytes_read == 10;
else if (atyp == 0x03)
return bytes_read > 4 && bytes_read == 4 + 1 + buf[4] + 2u;
else
return bytes_read == 22;
}
const uint8_t atyp = buf[3];
zmq_assert (atyp == 0x01 || atyp == 0x03 || atyp == 0x04);
if (atyp == 0x01)
return bytes_read == 10;
if (atyp == 0x03)
return bytes_read > 4 && bytes_read == 4 + 1 + buf[4] + 2u;
else
return bytes_read == 22;
}
zmq::socks_response_t zmq::socks_response_decoder_t::decode ()

View File

@ -770,7 +770,8 @@ int zmq::stream_engine_t::next_handshake_command (msg_t *msg_)
if (mechanism->status () == mechanism_t::ready) {
mechanism_ready ();
return pull_and_encode (msg_);
} else if (mechanism->status () == mechanism_t::error) {
}
if (mechanism->status () == mechanism_t::error) {
errno = EPROTO;
return -1;
} else {

View File

@ -153,8 +153,8 @@ socklen_t zmq::tcp_address_t::addrlen () const
{
if (address.generic.sa_family == AF_INET6)
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
@ -166,8 +166,8 @@ socklen_t zmq::tcp_address_t::src_addrlen () const
{
if (address.family () == AF_INET6)
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

View File

@ -147,8 +147,8 @@ long zmq::timers_t::timeout ()
if (cancelled_it == cancelled_timers.end ()) {
if (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

View File

@ -114,15 +114,14 @@ bool zmq::trie_t::add (unsigned char *prefix_, size_t size_)
zmq_assert (live_nodes == 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_)

View File

@ -104,7 +104,8 @@ int zmq::xsub_t::xsend (msg_t *msg_)
// when there are forwarding devices involved.
subscriptions.add (data + 1, size - 1);
return dist.send_to_all (msg_);
} else if (size > 0 && *data == 0) {
}
if (size > 0 && *data == 0) {
// Process unsubscribe message
if (subscriptions.rm (data + 1, size - 1))
return dist.send_to_all (msg_);

View File

@ -263,7 +263,7 @@ zmq::mechanism_t::status_t zap_client_common_handshake_t::status () const
{
if (state == ready)
return mechanism_t::ready;
else if (state == error_sent)
if (state == error_sent)
return mechanism_t::error;
else
return mechanism_t::handshaking;

View File

@ -685,10 +685,9 @@ const char *zmq_msg_gets (const zmq_msg_t *msg_, const char *property_)
value = metadata->get (std::string (property_));
if (value)
return value;
else {
errno = EINVAL;
return NULL;
}
errno = EINVAL;
return NULL;
}
// Polling.