Skip to content

Commit

Permalink
clang-tidy: don't use else after return
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Feb 6, 2025
1 parent 8b38703 commit 1f004a9
Show file tree
Hide file tree
Showing 29 changed files with 136 additions and 180 deletions.
8 changes: 3 additions & 5 deletions rak/socket_address.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,12 @@ socket_address::set_address_c_str(const char* a) {
if (sa_inet()->set_address_c_str(a)) {
sa_inet()->set_family();
return true;

} else if (sa_inet6()->set_address_c_str(a)) {
}
if (sa_inet6()->set_address_c_str(a)) {
sa_inet6()->set_family();
return true;

} else {
return false;
}
return false;
}

// Is the zero length really needed, should we require some length?
Expand Down
34 changes: 22 additions & 12 deletions rak/string_manip.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,10 @@ hexchar_to_value(char c) {
if (c >= '0' && c <= '9')
return c - '0';

else if (c >= 'A' && c <= 'F')
if (c >= 'A' && c <= 'F')
return 10 + c - 'A';

else
return 10 + c - 'a';

return 10 + c - 'a';
}

template <int pos, typename Value>
Expand All @@ -186,8 +185,7 @@ value_to_hexchar(Value v) {

if (v < 0xA)
return '0' + v;
else
return 'A' + v - 0xA;
return 'A' + v - 0xA;
}

template <typename InputIterator, typename OutputIterator>
Expand Down Expand Up @@ -218,12 +216,20 @@ copy_escape_html(InputIterator first1, InputIterator last1, OutputIterator first
if (std::isalpha(*first1, std::locale::classic()) ||
std::isdigit(*first1, std::locale::classic()) ||
*first1 == '-') {
if (first2 == last2) break; else *(first2++) = *first1;
if (first2 == last2)
break;
*(first2++) = *first1;

} else {
if (first2 == last2) break; else *(first2++) = '%';
if (first2 == last2) break; else *(first2++) = value_to_hexchar<1>(*first1);
if (first2 == last2) break; else *(first2++) = value_to_hexchar<0>(*first1);
if (first2 == last2)
break;
*(first2++) = '%';
if (first2 == last2)
break;
*(first2++) = value_to_hexchar<1>(*first1);
if (first2 == last2)
break;
*(first2++) = value_to_hexchar<0>(*first1);
}

++first1;
Expand Down Expand Up @@ -277,8 +283,12 @@ template <typename InputIterator, typename OutputIterator>
OutputIterator
transform_hex(InputIterator first1, InputIterator last1, OutputIterator first2, OutputIterator last2) {
while (first1 != last1) {
if (first2 == last2) break; else *(first2++) = value_to_hexchar<1>(*first1);
if (first2 == last2) break; else *(first2++) = value_to_hexchar<0>(*first1);
if (first2 == last2)
break;
*(first2++) = value_to_hexchar<1>(*first1);
if (first2 == last2)
break;
*(first2++) = value_to_hexchar<0>(*first1);

++first1;
}
Expand Down
14 changes: 5 additions & 9 deletions src/data/chunk_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,19 +364,15 @@ ChunkList::sync_options(ChunkListNode* node, int flags) {

if (flags & sync_safe)
return std::make_pair(MemoryChunk::sync_sync, true);
else
return std::make_pair(MemoryChunk::sync_async, true);
return std::make_pair(MemoryChunk::sync_async, true);
}
if (flags & sync_safe) {

} else if (flags & sync_safe) {

if (node->sync_triggered())
return std::make_pair(MemoryChunk::sync_sync, true);
else
return std::make_pair(MemoryChunk::sync_async, false);

} else {
return std::make_pair(MemoryChunk::sync_async, true);
return std::make_pair(MemoryChunk::sync_async, false);
}
return std::make_pair(MemoryChunk::sync_async, true);
}

// Using a rather simple algorithm for now. This should really be more
Expand Down
3 changes: 2 additions & 1 deletion src/data/hash_torrent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ HashTorrent::queue(bool quick) {
if (itr == m_ranges.end()) {
m_position = m_chunk_list->size();
break;
} else if (m_position < itr->first) {
}
if (m_position < itr->first) {
m_position = itr->first;
}

Expand Down
3 changes: 1 addition & 2 deletions src/dht/dht_router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ DhtRouter::get_node(const HashString& id) {
if (itr == m_nodes.end()) {
if (id == this->id())
return this;
else
return NULL;
return NULL;
}

return itr.node();
Expand Down
12 changes: 5 additions & 7 deletions src/dht/dht_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -693,14 +693,12 @@ DhtServer::failed_transaction(transaction_itr itr, bool quick) {
}

if (quick) {
return ++itr; // don't actually delete the transaction until the final timeout

} else {
drop_packet(transaction->packet());
delete itr->second;
m_transactions.erase(itr++);
return itr;
return ++itr; // don't actually delete the transaction until the final timeout
}
drop_packet(transaction->packet());
delete itr->second;
m_transactions.erase(itr++);
return itr;
}

void
Expand Down
4 changes: 2 additions & 2 deletions src/dht/dht_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ DhtTracker::add_peer(uint32_t addr, uint16_t port) {
m_peers[i].peer.port = compact.port;
m_lastSeen[i] = cachedTime.seconds();
return;

} else if (m_lastSeen[i] < minSeen) {
}
if (m_lastSeen[i] < minSeen) {
minSeen = m_lastSeen[i];
oldest = i;
}
Expand Down
3 changes: 1 addition & 2 deletions src/download/chunk_selector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ ChunkSelector::search_linear_range(const Bitfield* bf, rak::partial_queue* pq, u

if (wanted)
return search_linear_byte(pq, m_data->untouched_bitfield()->position(local), wanted);
else
return true;
return true;
}

// Take pointer to partial_queue
Expand Down
3 changes: 1 addition & 2 deletions src/net/socket_fd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ SocketFd::set_priority(priority_type p) {

if (m_ipv6_socket)
return setsockopt(m_fd, IPPROTO_IPV6, IPV6_TCLASS, &opt, sizeof(opt)) == 0;
else
return setsockopt(m_fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)) == 0;
return setsockopt(m_fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)) == 0;
}

bool
Expand Down
14 changes: 6 additions & 8 deletions src/net/socket_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ SocketStream::read_stream_throws(void* buf, uint32_t length) {
if (r < 0) {
if (rak::error_number::current().is_blocked_momentary())
return 0;
else if (rak::error_number::current().is_closed())
if (rak::error_number::current().is_closed())
throw close_connection();
else if (rak::error_number::current().is_blocked_prolonged())
if (rak::error_number::current().is_blocked_prolonged())
throw blocked_connection();
else
throw connection_error(rak::error_number::current().value());
throw connection_error(rak::error_number::current().value());
}

return r;
Expand All @@ -85,12 +84,11 @@ SocketStream::write_stream_throws(const void* buf, uint32_t length) {
if (r < 0) {
if (rak::error_number::current().is_blocked_momentary())
return 0;
else if (rak::error_number::current().is_closed())
if (rak::error_number::current().is_closed())
throw close_connection();
else if (rak::error_number::current().is_blocked_prolonged())
if (rak::error_number::current().is_blocked_prolonged())
throw blocked_connection();
else
throw connection_error(rak::error_number::current().value());
throw connection_error(rak::error_number::current().value());
}

return r;
Expand Down
12 changes: 5 additions & 7 deletions src/net/throttle_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,16 @@ ThrottleList::node_quota(ThrottleNode* node) {
// Returns max for signed integer to ensure we don't overflow
// claculations.
return std::numeric_limits<int32_t>::max();

} else if (!is_active(node)) {
}
if (!is_active(node)) {
throw internal_error(is_inactive(node) ?
"ThrottleList::node_quota(...) called on an inactive node." :
"ThrottleList::node_quota(...) could not find node.");

} else if (node->quota() + m_unallocatedQuota >= m_minChunkSize) {
}
if (node->quota() + m_unallocatedQuota >= m_minChunkSize) {
return node->quota() + m_unallocatedQuota;

} else {
return 0;
}
return 0;
}

void
Expand Down
11 changes: 5 additions & 6 deletions src/protocol/peer_connection_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -942,14 +942,13 @@ PeerConnectionBase::should_request() {
// || m_down->get_state() == ProtocolRead::READ_SKIP_PIECE)
return false;

else if (!m_download->delegator()->get_aggressive())
if (!m_download->delegator()->get_aggressive())
return true;

else
// We check if the peer is stalled, if it is not then we should
// request. If the peer is stalled then we only request if the
// download rate is below a certain value.
return m_downStall <= 1 || m_download->info()->down_rate()->rate() < (10 << 10);
// We check if the peer is stalled, if it is not then we should
// request. If the peer is stalled then we only request if the
// download rate is below a certain value.
return m_downStall <= 1 || m_download->info()->down_rate()->rate() < (10 << 10);
}

bool
Expand Down
36 changes: 14 additions & 22 deletions src/protocol/peer_connection_leech.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ PeerConnection<type>::read_message() {
m_down->set_last_command(ProtocolBase::KEEP_ALIVE);

return true;

} else if (buf->remaining() < 1) {
}
if (buf->remaining() < 1) {
buf->set_position_itr(beginning);
return false;

} else if (length > (1 << 20)) {
}
if (length > (1 << 20)) {
throw communication_error("PeerConnection::read_message() got an invalid message length.");
}

// We do not verify the message length of those with static
// length. A bug in the remote client causing the message start to
// be unsyncronized would in practically all cases be caught with
Expand Down Expand Up @@ -293,26 +293,19 @@ PeerConnection<type>::read_message() {
m_tryRequest = true;
down_chunk_finished();
return true;

} else {
m_down->set_state(ProtocolRead::READ_SKIP_PIECE);
m_down->throttle()->insert(m_peerChunks.download_throttle());
return false;
}

} else {

m_down->set_state(ProtocolRead::READ_SKIP_PIECE);
m_down->throttle()->insert(m_peerChunks.download_throttle());
return false;
}
if (down_chunk_from_buffer()) {
m_tryRequest = true;
down_chunk_finished();
return true;

} else {
m_down->set_state(ProtocolRead::READ_PIECE);
m_down->throttle()->insert(m_peerChunks.download_throttle());
return false;
}
}
m_down->set_state(ProtocolRead::READ_PIECE);
m_down->throttle()->insert(m_peerChunks.download_throttle());
return false;

case ProtocolBase::CANCEL:
if (!m_down->can_read_cancel_body())
Expand Down Expand Up @@ -401,10 +394,9 @@ PeerConnection<type>::event_read() {
if (m_down->buffer()->size_end() == read_size) {
m_down->buffer()->move_unused();
break;
} else {
m_down->buffer()->move_unused();
return;
}
m_down->buffer()->move_unused();
return;

case ProtocolRead::READ_PIECE:
if (type != Download::CONNECTION_LEECH)
Expand Down
20 changes: 9 additions & 11 deletions src/protocol/peer_connection_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ PeerConnectionMetadata::read_message() {
m_down->set_last_command(ProtocolBase::KEEP_ALIVE);

return true;

} else if (buf->remaining() < 1) {
}
if (buf->remaining() < 1) {
buf->set_position_itr(beginning);
return false;

} else if (length > (1 << 20)) {
}
if (length > (1 << 20)) {
throw communication_error("PeerConnection::read_message() got an invalid message length.");
}

m_down->set_last_command((ProtocolBase::Protocol)buf->peek_8());

// Ignore most messages, they aren't relevant for a metadata download.
Expand Down Expand Up @@ -251,10 +251,9 @@ PeerConnectionMetadata::event_read() {
if (m_down->buffer()->size_end() == read_size) {
m_down->buffer()->move_unused();
break;
} else {
m_down->buffer()->move_unused();
return;
}
m_down->buffer()->move_unused();
return;

case ProtocolRead::READ_EXTENSION:
if (!down_extension())
Expand Down Expand Up @@ -449,10 +448,9 @@ PeerConnectionMetadata::try_request_metadata_pieces() {
if (m_extensions->request_metadata_piece(p)) {
LT_LOG_METADATA_EVENTS("request metadata piece succeded", 0);
return true;
} else {
LT_LOG_METADATA_EVENTS("request metadata piece failed", 0);
return false;
}
LT_LOG_METADATA_EVENTS("request metadata piece failed", 0);
return false;
}

void
Expand Down
12 changes: 4 additions & 8 deletions src/protocol/request_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,11 @@ RequestList::calculate_pipe_size(uint32_t rate) {
if (!m_delegator->get_aggressive()) {
if (rate < 20)
return rate + 2;
else
return rate / 5 + 18;

} else {
if (rate < 10)
return rate / 5 + 1;
else
return rate / 10 + 2;
return rate / 5 + 18;
}
if (rate < 10)
return rate / 5 + 1;
return rate / 10 + 2;
}

}
3 changes: 1 addition & 2 deletions src/thread_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ thread_main::next_timeout_usec() {

if (!taskScheduler.empty())
return std::max(taskScheduler.top()->time() - cachedTime, rak::timer()).usec();
else
return rak::timer::from_seconds(60).usec();
return rak::timer::from_seconds(60).usec();
}

}
Loading

0 comments on commit 1f004a9

Please sign in to comment.