Skip to content

Commit

Permalink
fixes for new clang-tidy version
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Jan 23, 2025
1 parent 5b449ff commit bd2078e
Show file tree
Hide file tree
Showing 26 changed files with 65 additions and 72 deletions.
8 changes: 3 additions & 5 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2164,8 +2164,7 @@ namespace {

lsd_error_alert::lsd_error_alert(aux::stack_allocator&, error_code const& ec
, address const& local)
: alert()
, local_address(local)
: local_address(local)
, error(ec)
{}

Expand Down Expand Up @@ -2253,8 +2252,7 @@ namespace {
, std::vector<dht_routing_bucket> table
, std::vector<dht_lookup> requests
, sha1_hash id, udp::endpoint ep)
: alert()
, active_requests(std::move(requests))
: active_requests(std::move(requests))
, routing_table(std::move(table))
, nid(id)
, local_endpoint(ep)
Expand Down Expand Up @@ -2549,7 +2547,7 @@ namespace {

bdecode_node dht_direct_response_alert::response() const
{
if (m_response_size == 0) return bdecode_node();
if (m_response_size == 0) return {};
char const* start = m_alloc.get().ptr(m_response_idx);
char const* end = start + m_response_size;
error_code ec;
Expand Down
16 changes: 8 additions & 8 deletions src/bdecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ namespace aux {

// otherwise, return a reference to this node, but without
// being an owning root node
return bdecode_node(&m_tokens[0], m_buffer, m_buffer_size, m_token_idx);
return {&m_tokens[0], m_buffer, m_buffer_size, m_token_idx};
}

void bdecode_node::clear()
Expand Down Expand Up @@ -443,7 +443,7 @@ namespace aux {
m_last_token = token;
m_last_index = i;

return bdecode_node(tokens, m_buffer, m_buffer_size, token);
return {tokens, m_buffer, m_buffer_size, token};
}

string_view bdecode_node::list_string_value_at(int i
Expand Down Expand Up @@ -611,7 +611,7 @@ namespace aux {
token += t.next_item;
TORRENT_ASSERT(tokens[token].type != bdecode_token::end);

return bdecode_node(tokens, m_buffer, m_buffer_size, token);
return {tokens, m_buffer, m_buffer_size, token};
}

// skip key
Expand All @@ -622,23 +622,23 @@ namespace aux {
token += tokens[token].next_item;
}

return bdecode_node();
return {};
}

bdecode_node bdecode_node::dict_find_list(string_view key) const
{
bdecode_node ret = dict_find(key);
if (ret.type() == bdecode_node::list_t)
return ret;
return bdecode_node();
return {};
}

bdecode_node bdecode_node::dict_find_dict(string_view key) const
{
bdecode_node ret = dict_find(key);
if (ret.type() == bdecode_node::dict_t)
return ret;
return bdecode_node();
return {};
}

bdecode_node bdecode_node::dict_find_string(string_view key) const
Expand All @@ -654,7 +654,7 @@ namespace aux {
bdecode_node ret = dict_find(key);
if (ret.type() == bdecode_node::int_t)
return ret;
return bdecode_node();
return {};
}

string_view bdecode_node::dict_find_string_value(string_view key
Expand Down Expand Up @@ -702,7 +702,7 @@ namespace aux {
TORRENT_ASSERT(t.type == bdecode_token::string
|| t.type == bdecode_token::long_string);

return string_view(m_buffer + t.offset + t.start_offset(), size);
return {m_buffer + t.offset + t.start_offset(), size};
}

std::ptrdiff_t bdecode_node::string_offset() const
Expand Down
2 changes: 1 addition & 1 deletion src/disabled_disk_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct TORRENT_EXTRA_EXPORT disabled_disk_io final
storage_holder new_torrent(storage_params const&
, std::shared_ptr<void> const&) override
{
return storage_holder(storage_index_t(0), *this);
return {storage_index_t(0), *this};
}

void remove_torrent(storage_index_t) override {}
Expand Down
6 changes: 3 additions & 3 deletions src/enum_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,15 +1352,15 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
if (sock < 0)
{
ec = error_code(errno, system_category());
return std::vector<ip_route>();
return {};
}
socket_closer c1(sock);

int dgram_sock = ::socket(AF_INET, SOCK_DGRAM, 0);
if (dgram_sock < 0)
{
ec = error_code(errno, system_category());
return std::vector<ip_route>();
return {};
}
socket_closer c2(dgram_sock);

Expand All @@ -1380,7 +1380,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
}) != 0)
{
ec = error_code(errno, system_category());
return std::vector<ip_route>();
return {};
}
#elif TORRENT_USE_GRTTABLE

Expand Down
2 changes: 1 addition & 1 deletion src/escape_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ namespace {
else if (in == '1')
inbuf[j] = 'I' - 'A';
else
return std::string();
return {};
TORRENT_ASSERT(inbuf[j] == (inbuf[j] & 0x1f));
}

Expand Down
4 changes: 2 additions & 2 deletions src/file_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,15 +855,15 @@ namespace aux {
sha1_hash file_storage::hash(file_index_t const index) const
{
TORRENT_ASSERT_PRECOND(index >= file_index_t{} && index < end_file());
if (index >= m_file_hashes.end_index()) return sha1_hash();
if (index >= m_file_hashes.end_index()) return {};
return sha1_hash(m_file_hashes[index]);
}
#endif

sha256_hash file_storage::root(file_index_t const index) const
{
TORRENT_ASSERT_PRECOND(index >= file_index_t{} && index < end_file());
if (m_files[index].root == nullptr) return sha256_hash();
if (m_files[index].root == nullptr) return {};
return sha256_hash(m_files[index].root);
}

Expand Down
4 changes: 2 additions & 2 deletions src/hash_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ bool validate_hash_request(hash_request const& hr, file_storage const& fs)
int const piece_tree_num_layers
= num_layers - piece_tree_root_layer - m_piece_layer;

return hash_request(fidx
return {fidx
, m_piece_layer
, i * 512
, std::min(512, merkle_num_leafs(int(m_files.file_num_pieces(fidx) - i * 512)))
, layers_to_verify({ fidx, piece_tree_root }) + piece_tree_num_layers);
, layers_to_verify({ fidx, piece_tree_root }) + piece_tree_num_layers};
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/identify_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace {
|| (id[3] < '0') || (id[4] < '0')
|| (id[5] < '0') || (id[6] < '0')
|| id[7] != '-')
return std::optional<fingerprint>();
return {};

ret.name[0] = char(id[1]);
ret.name[1] = char(id[2]);
Expand All @@ -57,7 +57,7 @@ namespace {
ret.revision_version = decode_digit(id[5]);
ret.tag_version = decode_digit(id[6]);

return std::optional<fingerprint>(ret);
return {ret};
}

// checks if a peer id can possibly contain a shadow-style
Expand All @@ -67,21 +67,21 @@ namespace {
fingerprint ret("..", 0, 0, 0, 0);

if (!aux::is_alpha(char(id[0])) && !aux::is_digit(char(id[0])))
return std::optional<fingerprint>();
return {};

if (std::equal(id.begin() + 4, id.begin() + 6, "--"))
{
if ((id[1] < '0') || (id[2] < '0')
|| (id[3] < '0'))
return std::optional<fingerprint>();
return {};
ret.major_version = decode_digit(id[1]);
ret.minor_version = decode_digit(id[2]);
ret.revision_version = decode_digit(id[3]);
}
else
{
if (id[8] != 0 || id[1] > 127 || id[2] > 127 || id[3] > 127)
return std::optional<fingerprint>();
return {};
ret.major_version = id[1];
ret.minor_version = id[2];
ret.revision_version = id[3];
Expand All @@ -91,7 +91,7 @@ namespace {
ret.name[1] = 0;

ret.tag_version = 0;
return std::optional<fingerprint>(ret);
return {ret};
}

// checks if a peer id can possibly contain a mainline-style
Expand All @@ -107,9 +107,9 @@ namespace {
if (std::sscanf(ids, "%1c%3d-%3d-%3d--", &ret.name[0], &ret.major_version, &ret.minor_version
, &ret.revision_version) != 4
|| !aux::is_print(ret.name[0]))
return std::optional<fingerprint>();
return {};

return std::optional<fingerprint>(ret);
return {ret};
}

struct map_entry
Expand Down
2 changes: 1 addition & 1 deletion src/kademlia/dht_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace libtorrent::dht {

node_ids_t extract_node_ids(bdecode_node const& e, string_view key)
{
if (e.type() != bdecode_node::dict_t) return node_ids_t();
if (e.type() != bdecode_node::dict_t) return {};
node_ids_t ret;
// first look for an old-style nid
auto const old_nid = e.dict_find_string_value(key);
Expand Down
2 changes: 1 addition & 1 deletion src/kademlia/dht_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace {
struct dht_mutable_item : dht_immutable_item
{
signature sig{};
sequence_number seq{};
sequence_number seq;
public_key key{};
std::string salt;
};
Expand Down
6 changes: 2 additions & 4 deletions src/kademlia/dht_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,9 @@ namespace libtorrent::dht {
{
explicit get_immutable_item_ctx(int traversals)
: active_traversals(traversals)
, item_posted(false)
{}
int active_traversals;
bool item_posted;
bool item_posted = false;
};

// these functions provide a slightly higher level
Expand Down Expand Up @@ -384,11 +383,10 @@ namespace libtorrent::dht {
{
explicit put_item_ctx(int traversals)
: active_traversals(traversals)
, response_count(0)
{}

int active_traversals;
int response_count;
int response_count = 0;
};

void put_immutable_item_callback(int responses, std::shared_ptr<put_item_ctx> ctx
Expand Down
10 changes: 5 additions & 5 deletions src/merkle_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ namespace {
: block_layer_start();

if (m_mode == mode_t::piece_layer && idx >= merkle_get_first_child(start))
return sha256_hash();
return {};

int layer_size = 1;
while (idx < start)
Expand Down Expand Up @@ -758,16 +758,16 @@ namespace {
{
case mode_t::uninitialized_tree:
case mode_t::empty_tree:
return bitfield(m_num_blocks, m_num_blocks == 1);
return {m_num_blocks, m_num_blocks == 1};
case mode_t::piece_layer:
return bitfield(m_num_blocks, piece_levels() == 0);
return {m_num_blocks, piece_levels() == 0};
case mode_t::block_layer:
return bitfield(m_num_blocks, true);
return {m_num_blocks, true};
case mode_t::full_tree:
return m_block_verified;
}
TORRENT_ASSERT_FAIL();
return bitfield();
return {};
}

bool merkle_tree::is_complete() const
Expand Down
2 changes: 1 addition & 1 deletion src/mmap_disk_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ TORRENT_EXPORT std::unique_ptr<disk_interface> mmap_disk_io_constructor(
auto storage = std::make_shared<aux::mmap_storage>(params, m_file_pool);
storage->set_owner(owner);
storage_index_t const idx = m_torrents.add(std::move(storage));
return storage_holder(idx, *this);
return {idx, *this};
}

void mmap_disk_io::remove_torrent(storage_index_t const idx)
Expand Down
10 changes: 5 additions & 5 deletions src/mmap_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ error_code translate_error(std::error_code const& err, bool const write)
{
#ifdef TORRENT_WINDOWS
if (err == std::error_code(sig::seh_errors::in_page_error))
return error_code(boost::system::errc::no_space_on_device, generic_category());
return {boost::system::errc::no_space_on_device, generic_category()};
#else
if (err == std::error_code(sig::errors::bus))
return error_code(boost::system::errc::no_space_on_device, generic_category());
return {boost::system::errc::no_space_on_device, generic_category()};
#endif
}

#if BOOST_VERSION >= 107700

#ifdef TORRENT_WINDOWS
if (err == std::error_code(sig::seh_errors::in_page_error))
return error_code(boost::system::errc::io_error, generic_category());
return {boost::system::errc::io_error, generic_category()};
#else
if (err == std::error_code(sig::errors::bus))
return error_code(boost::system::errc::io_error, generic_category());
return {boost::system::errc::io_error, generic_category()};
#endif

return err;
#else

return error_code(boost::system::errc::io_error, generic_category());
return {boost::system::errc::io_error, generic_category()};

#endif
}
Expand Down
4 changes: 2 additions & 2 deletions src/packet_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ namespace aux {
INVARIANT_CHECK;
// TODO: use compare_less_wrap for this comparison as well
if (idx >= m_first + m_capacity)
return packet_ptr();
return {};

if (compare_less_wrap(idx, m_first, 0xffff))
return packet_ptr();
return {};

std::size_t const mask = m_capacity - 1;
packet_ptr old_value = std::move(m_storage[idx & mask]);
Expand Down
4 changes: 2 additions & 2 deletions src/part_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ namespace libtorrent::aux {
{
std::string const fn = combine_path(m_path, m_name);
try {
return aux::file_handle(fn, 0, mode);
return {fn, 0, mode};
}
catch (storage_error const& e)
{
Expand All @@ -255,7 +255,7 @@ namespace libtorrent::aux {
ec.clear();
create_directories(m_path, ec);
if (ec) return {};
return aux::file_handle(fn, 0, mode);
return {fn, 0, mode};
}
return {};
}
Expand Down
Loading

0 comments on commit bd2078e

Please sign in to comment.