Skip to content

Commit

Permalink
Fix or suppress Windows build warnings (#4195)
Browse files Browse the repository at this point in the history
* Fix conversion warn in message_deserializer.cpp

Fix warning C4267: '+=': conversion from 'size_t' to 'unsigned int',
possible loss of data

* Fix conversion warn in inproc.cpp

Fix warning C4267: '+=': conversion from 'size_t' to 'unsigned int',
possible loss of data

* Add std:: namespace prefix to all size_t declarations in socket.?pp

* Suppress argument conversion in socket.cpp

Suppresses the warning C4267: 'argument': conversion from 'size_t' to
'unsigned short', possible loss of data

* Fix possible signed int issue in socket.cpp

Suppress warning C4018: '>=': signed/unsigned mismatch and ensure the
counted_connections is an absolute number before its comparison.

* Suppress data loss warn in peer_container.cpp

Suppress warning C4267: 'initializing': conversion from 'size_t' to
'unsigned int', possible loss of data

* Suppress signed/unsigned warn in peer_container.cpp

Suppress warning C4018: '<': signed/unsigned mismatch

* Refactor nano::to_stat_detail

Fix warning C4700: uninitialized local variable 'result' used. Also
removed the unreachable break statements and add an assert_debug for
ensuring the nano::stat::detail::_last is never returned.

* Removed an unreachable argument variable in blockprocessor.cpp

Fix warning C4101: 'e': unreferenced local variable

Signed-off-by: Thiago Silva <[email protected]>

* Tentative to fix the wrongly infered compiler warn in bootstrap_ascending.cpp

Address warning C4267: '=': conversion from 'size_t' to 'uint8_t',
possible loss of data. The compiler infers there is a conversion, but no
conversion is done. Suppressed the warning message.

* Fix conversion warn on var initialization in node.cpp

Fix warning C4244: 'initializing': conversion from 'double' to
'uint64_t', possible loss of data

* Fix argument conversion warn in node.cpp

Fix warning C4244: 'argument': conversion from 'uint64_t' to 'const
_Ty', possible loss of data

---------

Signed-off-by: Thiago Silva <[email protected]>
  • Loading branch information
thsfs authored Mar 30, 2023
1 parent fde815f commit 23c6bb5
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 41 deletions.
4 changes: 2 additions & 2 deletions nano/core_test/message_deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ auto message_deserializer_success_checker (message_type & message_original) -> v
// Data used to simulate the incoming buffer to be deserialized, the offset tracks how much has been read from the input_source
// as the read function is called first to read the header, then called again to read the payload.
std::vector<uint8_t> input_source;
auto offset = 0u;
std::size_t offset{ 0 };

// Message Deserializer with the query function tweaked to read from the `input_source`.
auto const message_deserializer = std::make_shared<nano::transport::message_deserializer> (nano::dev::network_params.network, filter, block_uniquer, vote_uniquer,
[&input_source, &offset] (std::shared_ptr<std::vector<uint8_t>> const & data_a, size_t size_a, std::function<void (boost::system::error_code const &, std::size_t)> callback_a) {
[&input_source, &offset] (std::shared_ptr<std::vector<uint8_t>> const & data_a, std::size_t size_a, std::function<void (boost::system::error_code const &, std::size_t)> callback_a) {
debug_assert (input_source.size () >= size_a);
data_a->resize (size_a);
auto const copy_start = input_source.begin () + offset;
Expand Down
6 changes: 3 additions & 3 deletions nano/core_test/peer_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ TEST (channels, fill_random_part)
{
nano::test::system system{ 1 };
std::array<nano::endpoint, 8> target;
unsigned half{ target.size () / 2 };
for (unsigned i = 0; i < half; ++i)
std::size_t half = target.size () / 2;
for (std::size_t i = 0; i < half; ++i)
{
auto outer_node = nano::test::add_outer_node (system);
ASSERT_NE (nullptr, nano::test::establish_tcp (system, *system.nodes[0], outer_node->network.endpoint ()));
Expand Down Expand Up @@ -197,7 +197,7 @@ TEST (peer_container, list_fanout)
ASSERT_EQ (2, node->network.list (node->network.fanout ()).size ());

unsigned number_of_peers = 10;
for (auto i = 2; i < number_of_peers; ++i)
for (unsigned i = 2; i < number_of_peers; ++i)
{
add_peer ();
}
Expand Down
2 changes: 1 addition & 1 deletion nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ std::optional<nano::process_return> nano::block_processor::add_blocking (std::sh
{
result = future.get ();
}
catch (std::future_error const & e)
catch (std::future_error const &)
{
}
return result;
Expand Down
3 changes: 1 addition & 2 deletions nano/node/bootstrap/bootstrap_ascending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ void nano::bootstrap_ascending::send (std::shared_ptr<nano::transport::channel>
nano::asc_pull_req::blocks_payload request_payload;
request_payload.start = tag.start;
request_payload.count = pull_count;
request_payload.start_type = tag.type == async_tag::query_type::blocks_by_hash ? nano::asc_pull_req::hash_type::block : nano::asc_pull_req::hash_type::account;

request_payload.start_type = (tag.type == async_tag::query_type::blocks_by_hash) ? nano::asc_pull_req::hash_type::block : nano::asc_pull_req::hash_type::account;
request.payload = request_payload;
request.update_header ();

Expand Down
4 changes: 2 additions & 2 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,10 +881,10 @@ void nano::node::ongoing_bootstrap ()
{
last_sample_time = last_record->first;
}
uint64_t time_since_last_sample = std::chrono::duration_cast<std::chrono::seconds> (std::chrono::system_clock::now ().time_since_epoch ()).count () - last_sample_time / std::pow (10, 9); // Nanoseconds to seconds
uint64_t time_since_last_sample = std::chrono::duration_cast<std::chrono::seconds> (std::chrono::system_clock::now ().time_since_epoch ()).count () - static_cast<uint64_t> (last_sample_time / std::pow (10, 9)); // Nanoseconds to seconds
if (time_since_last_sample + 60 * 60 < std::numeric_limits<uint32_t>::max ())
{
frontiers_age = std::max<uint32_t> (time_since_last_sample + 60 * 60, network_params.bootstrap.default_frontiers_age_seconds);
frontiers_age = std::max<uint32_t> (static_cast<uint32_t> (time_since_last_sample + 60 * 60), network_params.bootstrap.default_frontiers_age_seconds);
}
}
else if (previous_bootstrap_count % 4 != 0)
Expand Down
4 changes: 2 additions & 2 deletions nano/node/transport/inproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class message_visitor_inbound : public nano::message_visitor
*/
void nano::transport::inproc::channel::send_buffer (nano::shared_const_buffer const & buffer_a, std::function<void (boost::system::error_code const &, std::size_t)> const & callback_a, nano::transport::buffer_drop_policy drop_policy_a)
{
auto offset = 0u;
auto const buffer_read_fn = [&offset, buffer_v = buffer_a.to_bytes ()] (std::shared_ptr<std::vector<uint8_t>> const & data_a, size_t size_a, std::function<void (boost::system::error_code const &, std::size_t)> callback_a) {
std::size_t offset{ 0 };
auto const buffer_read_fn = [&offset, buffer_v = buffer_a.to_bytes ()] (std::shared_ptr<std::vector<uint8_t>> const & data_a, std::size_t size_a, std::function<void (boost::system::error_code const &, std::size_t)> callback_a) {
debug_assert (buffer_v.size () >= (offset + size_a));
data_a->resize (size_a);
auto const copy_start = buffer_v.begin () + offset;
Expand Down
17 changes: 9 additions & 8 deletions nano/node/transport/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <boost/format.hpp>

#include <cstdint>
#include <cstdlib>
#include <iterator>
#include <limits>
#include <memory>
Expand Down Expand Up @@ -243,7 +244,7 @@ void nano::transport::socket::checkup ()
});
}

void nano::transport::socket::read_impl (std::shared_ptr<std::vector<uint8_t>> const & data_a, size_t size_a, std::function<void (boost::system::error_code const &, std::size_t)> callback_a)
void nano::transport::socket::read_impl (std::shared_ptr<std::vector<uint8_t>> const & data_a, std::size_t size_a, std::function<void (boost::system::error_code const &, std::size_t)> callback_a)
{
// Increase timeout to receive TCP header (idle server socket)
auto const prev_timeout = get_default_timeout_value ();
Expand Down Expand Up @@ -352,29 +353,29 @@ void nano::transport::server_socket::close ()
}));
}

boost::asio::ip::network_v6 nano::transport::socket_functions::get_ipv6_subnet_address (boost::asio::ip::address_v6 const & ip_address, size_t network_prefix)
boost::asio::ip::network_v6 nano::transport::socket_functions::get_ipv6_subnet_address (boost::asio::ip::address_v6 const & ip_address, std::size_t network_prefix)
{
return boost::asio::ip::make_network_v6 (ip_address, network_prefix);
return boost::asio::ip::make_network_v6 (ip_address, static_cast<unsigned short> (network_prefix));
}

boost::asio::ip::address nano::transport::socket_functions::first_ipv6_subnet_address (boost::asio::ip::address_v6 const & ip_address, size_t network_prefix)
boost::asio::ip::address nano::transport::socket_functions::first_ipv6_subnet_address (boost::asio::ip::address_v6 const & ip_address, std::size_t network_prefix)
{
auto range = get_ipv6_subnet_address (ip_address, network_prefix).hosts ();
debug_assert (!range.empty ());
return *(range.begin ());
}

boost::asio::ip::address nano::transport::socket_functions::last_ipv6_subnet_address (boost::asio::ip::address_v6 const & ip_address, size_t network_prefix)
boost::asio::ip::address nano::transport::socket_functions::last_ipv6_subnet_address (boost::asio::ip::address_v6 const & ip_address, std::size_t network_prefix)
{
auto range = get_ipv6_subnet_address (ip_address, network_prefix).hosts ();
debug_assert (!range.empty ());
return *(--range.end ());
}

size_t nano::transport::socket_functions::count_subnetwork_connections (
std::size_t nano::transport::socket_functions::count_subnetwork_connections (
nano::transport::address_socket_mmap const & per_address_connections,
boost::asio::ip::address_v6 const & remote_address,
size_t network_prefix)
std::size_t network_prefix)
{
auto range = get_ipv6_subnet_address (remote_address, network_prefix).hosts ();
if (range.empty ())
Expand Down Expand Up @@ -412,7 +413,7 @@ bool nano::transport::server_socket::limit_reached_for_incoming_ip_connections (
return false;
}
auto const address_connections_range = connections_per_address.equal_range (new_connection->remote.address ());
auto const counted_connections = std::distance (address_connections_range.first, address_connections_range.second);
auto const counted_connections = static_cast<std::size_t> (std::abs (std::distance (address_connections_range.first, address_connections_range.second)));
return counted_connections >= node.network_params.network.max_peers_per_ip;
}

Expand Down
10 changes: 5 additions & 5 deletions nano/node/transport/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class socket : public std::enable_shared_from_this<nano::transport::socket>
void set_last_completion ();
void set_last_receive_time ();
void checkup ();
void read_impl (std::shared_ptr<std::vector<uint8_t>> const & data_a, size_t size_a, std::function<void (boost::system::error_code const &, std::size_t)> callback_a);
void read_impl (std::shared_ptr<std::vector<uint8_t>> const & data_a, std::size_t size_a, std::function<void (boost::system::error_code const &, std::size_t)> callback_a);

private:
type_t type_m{ type_t::undefined };
Expand All @@ -190,10 +190,10 @@ using address_socket_mmap = std::multimap<boost::asio::ip::address, std::weak_pt

namespace socket_functions
{
boost::asio::ip::network_v6 get_ipv6_subnet_address (boost::asio::ip::address_v6 const &, size_t);
boost::asio::ip::address first_ipv6_subnet_address (boost::asio::ip::address_v6 const &, size_t);
boost::asio::ip::address last_ipv6_subnet_address (boost::asio::ip::address_v6 const &, size_t);
size_t count_subnetwork_connections (nano::transport::address_socket_mmap const &, boost::asio::ip::address_v6 const &, size_t);
boost::asio::ip::network_v6 get_ipv6_subnet_address (boost::asio::ip::address_v6 const &, std::size_t);
boost::asio::ip::address first_ipv6_subnet_address (boost::asio::ip::address_v6 const &, std::size_t);
boost::asio::ip::address last_ipv6_subnet_address (boost::asio::ip::address_v6 const &, std::size_t);
std::size_t count_subnetwork_connections (nano::transport::address_socket_mmap const &, boost::asio::ip::address_v6 const &, std::size_t);
}

/** Socket class for TCP servers */
Expand Down
18 changes: 2 additions & 16 deletions nano/secure/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,51 +740,37 @@ void nano::generate_cache::enable_all ()

nano::stat::detail nano::to_stat_detail (nano::process_result process_result)
{
nano::stat::detail result;
switch (process_result)
{
case process_result::progress:
return nano::stat::detail::progress;
break;
case process_result::bad_signature:
return nano::stat::detail::bad_signature;
break;
case process_result::old:
return nano::stat::detail::old;
break;
case process_result::negative_spend:
return nano::stat::detail::negative_spend;
break;
case process_result::fork:
return nano::stat::detail::fork;
break;
case process_result::unreceivable:
return nano::stat::detail::unreceivable;
break;
case process_result::gap_previous:
return nano::stat::detail::gap_previous;
break;
case process_result::gap_source:
return nano::stat::detail::gap_source;
break;
case process_result::gap_epoch_open_pending:
return nano::stat::detail::gap_epoch_open_pending;
break;
case process_result::opened_burn_account:
return nano::stat::detail::opened_burn_account;
break;
case process_result::balance_mismatch:
return nano::stat::detail::balance_mismatch;
break;
case process_result::representative_mismatch:
return nano::stat::detail::representative_mismatch;
break;
case process_result::block_position:
return nano::stat::detail::block_position;
break;
case process_result::insufficient_work:
return nano::stat::detail::insufficient_work;
break;
}
return result;
debug_assert (false && "There should be always a defined nano::stat::detail that is not _last");
return nano::stat::detail::_last;
}

0 comments on commit 23c6bb5

Please sign in to comment.