Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more clang-tidy fixes #299

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/net/protocol_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ inline bool
ProtocolBuffer<tmpl_size>::consume(difference_type v) {
m_position += v;

if (remaining())
return false;

return true;
return !static_cast<bool>(remaining());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it more difficult to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about removing the cast and just returning

return !remaining();

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the style I used originally makes it very clear what is happening at a glance, while you have to think more with the compact style you are suggesting.

}

template <uint16_t tmpl_size>
Expand Down
2 changes: 1 addition & 1 deletion src/net/socket_listen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ socket_listen::open(sa_unique_ptr&& sap, uint16_t first_port, uint16_t last_port
throw internal_error("socket_listen::open: socket address is inet without v4only flag");

if (first_port == 0 || last_port == 0 || start_port == 0 ||
!(first_port <= last_port && first_port <= start_port && start_port <= last_port))
first_port > last_port || first_port > start_port || start_port > last_port)
throw internal_error("socket_listen::open: port range not valid");

int fd = fd_open(open_flags);
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/handshake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ Handshake::read_port() {

void
Handshake::read_done() {
if (m_readDone != false)
if (m_readDone)
throw internal_error("Handshake::read_done() m_readDone != false.");

// if (m_peerInfo->supports_extensions() && m_extensions->is_initial_handshake())
Expand Down Expand Up @@ -1171,7 +1171,7 @@ void
Handshake::write_bitfield() {
const Bitfield* bitfield = m_download->file_list()->bitfield();

if (m_writeDone != false)
if (m_writeDone)
throw internal_error("Handshake::event_write() m_writeDone != false.");

if (m_writeBuffer.remaining())
Expand Down
3 changes: 1 addition & 2 deletions src/torrent/connection_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ resolve_host(const char* host, int family, int socktype, ConnectionManager::slot
thread_base::release_global_lock();

rak::address_info* ai;
int err;

if ((err = rak::address_info::get_address_info(host, family, socktype, &ai)) != 0) {
if (int err = rak::address_info::get_address_info(host, family, socktype, &ai); err != 0) {
if (manager->main_thread_main()->is_current())
thread_base::acquire_global_lock();

Expand Down
14 changes: 4 additions & 10 deletions src/torrent/data/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,16 @@ Block::Block() :

inline BlockTransfer*
Block::find(const PeerInfo* p) {
BlockTransfer* transfer;

if ((transfer = find_queued(p)) != NULL)
if (auto transfer = find_queued(p))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style we use is to always check against nullptr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. this is a C++17 feature.

Would you prefer

auto transfer = find_queue(p);
if (transfer != nullptr)

Copy link
Owner

@rakshasa rakshasa Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but add an empty line between them.

return transfer;
else
return find_transfer(p);
return find_transfer(p);
}

inline const BlockTransfer*
Block::find(const PeerInfo* p) const {
const BlockTransfer* transfer;

if ((transfer = find_queued(p)) != NULL)
if (auto transfer = find_queued(p))
return transfer;
else
return find_transfer(p);
return find_transfer(p);
}

inline void
Expand Down
2 changes: 1 addition & 1 deletion src/torrent/download/choke_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ choke_queue::move_connections(choke_queue* src, choke_queue* dest, DownloadMain*

void
choke_manager_allocate_slots(choke_queue::iterator first, choke_queue::iterator last,
uint32_t max, uint32_t* weights, choke_queue::target_type* target) {
uint32_t max, const uint32_t* weights, choke_queue::target_type* target) {
// Sorting the connections from the lowest to highest value.
// TODO: std::sort(first, last, choke_manager_less);

Expand Down
4 changes: 2 additions & 2 deletions src/torrent/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ class LIBTORRENT_EXPORT Object {
void swap_same_type(Object& left, Object& right);

private:
inline bool check(map_type::const_iterator itr, type_type t) const { return itr != _map().end() && itr->second.type() == t; }
inline void check_throw(type_type t) const { if (t != type()) throw bencode_error("Wrong object type."); }
bool check(map_type::const_iterator itr, type_type t) const { return itr != _map().end() && itr->second.type() == t; }
void check_throw(type_type t) const { if (t != type()) throw bencode_error("Wrong object type."); }

template <typename T> void check_value_throw(const char* err_msg) const;

Expand Down
2 changes: 1 addition & 1 deletion src/torrent/tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class LIBTORRENT_EXPORT Tracker {

inline bool
Tracker::can_request_state() const {
return !(is_busy() && latest_event() != EVENT_SCRAPE) && is_usable();
return (!is_busy() || latest_event() == EVENT_SCRAPE) && is_usable();
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/torrent/utils/thread_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class LIBTORRENT_EXPORT thread_base {
slot_void& slot_do_work() { return m_slot_do_work; }
slot_timer& slot_next_timeout() { return m_slot_next_timeout; }

static inline int global_queue_size() { return m_global.waiting; }
static int global_queue_size() { return m_global.waiting; }

static inline void acquire_global_lock();
static inline bool trylock_global_lock();
Expand Down
4 changes: 2 additions & 2 deletions src/torrent/utils/uri_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#include "rak/string_manip.h"

namespace torrent { namespace utils {
namespace torrent::utils {

inline bool
is_unreserved_uri_char(char c) {
Expand Down Expand Up @@ -196,4 +196,4 @@ uri_parse_query_str(const char* query, uri_query_state& state) {
uri_parse_query_str(std::string(query), state);
}

}}
}
4 changes: 2 additions & 2 deletions src/torrent/utils/uri_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <torrent/common.h>
#include <torrent/exceptions.h>

namespace torrent { namespace utils {
namespace torrent::utils {

typedef std::vector<std::string> uri_resource_list;
typedef std::vector<std::string> uri_query_list;
Expand Down Expand Up @@ -91,6 +91,6 @@ class LIBTORRENT_EXPORT uri_error : public ::torrent::input_error {
uri_error(const std::string& msg) : ::torrent::input_error(msg) {}
};

}}
}

#endif