fixing sign-conversion warnings, part 20 (#1745)

fixing sign-conversion warnings, part 20
This commit is contained in:
Alden Torres 2017-02-22 23:28:25 -05:00 committed by Arvid Norberg
parent 7a8ffc2f2d
commit 847792854d
8 changed files with 19 additions and 9 deletions

View File

@ -553,7 +553,7 @@ namespace libtorrent
void get_cache_info(torrent_handle h, cache_status* ret, int flags) const;
void set_peer_id(peer_id const& id);
void set_key(int key);
void set_key(std::uint32_t key);
std::uint16_t listen_port() const override;
std::uint16_t ssl_listen_port() const override;
@ -875,7 +875,7 @@ namespace libtorrent
// the key is an id that is used to identify the
// client with the tracker only. It is randomized
// at startup
int m_key = 0;
std::uint32_t m_key = 0;
// posts a notification when the set of local IPs changes
ip_change_notifier m_ip_notifier;

View File

@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <algorithm> // for copy
#include <cstring> // for memcpy
#include <type_traits>
#include <iterator>
#include "assert.hpp"
@ -80,11 +81,19 @@ namespace libtorrent
|| std::is_enum<In>::value>::type>
inline void write_impl(In data, OutIt& start)
{
// Note: the test for [OutItT==void] below is necessary because
// in C++11 std::back_insert_iterator::value_type is void.
// This could change in C++17 or above
using OutItT = typename std::iterator_traits<OutIt>::value_type;
using Byte = typename std::conditional<
std::is_same<OutItT, void>::value, char, OutItT>::type;
static_assert(sizeof(Byte) == 1, "wrong iterator or pointer type");
T val = static_cast<T>(data);
TORRENT_ASSERT(data == static_cast<In>(val));
for (int i = int(sizeof(T)) - 1; i >= 0; --i)
{
*start = static_cast<unsigned char>((val >> (i * 8)) & 0xff);
*start = static_cast<Byte>((val >> (i * 8)) & 0xff);
++start;
}
}

View File

@ -109,7 +109,7 @@ namespace libtorrent
inline packet_ptr create_packet(int const size)
{
packet* p = static_cast<packet*>(std::malloc(sizeof(packet) + size));
packet* p = static_cast<packet*>(std::malloc(sizeof(packet) + aux::numeric_cast<std::uint16_t>(size)));
if (p == nullptr) aux::throw_ex<std::bad_alloc>();
new (p) packet();
p->allocated = aux::numeric_cast<std::uint16_t>(size);

View File

@ -581,7 +581,7 @@ namespace libtorrent
// sets the key sent to trackers. If it's not set, it is initialized
// by libtorrent. The key may be used by the tracker to identify the
// peer potentially across you changing your IP.
void set_key(int key);
void set_key(std::uint32_t key);
// built-in peer classes
static constexpr peer_class_t global_peer_class_id{0};

View File

@ -750,7 +750,7 @@ namespace libtorrent
return sync_call_ret<peer_id>(&session_impl::get_peer_id);
}
void session_handle::set_key(int key)
void session_handle::set_key(std::uint32_t key)
{
async_call(&session_impl::set_key, key);
}

View File

@ -2913,7 +2913,7 @@ namespace aux {
m_peer_id = id;
}
void session_impl::set_key(int key)
void session_impl::set_key(std::uint32_t key)
{
m_key = key;
}

View File

@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/timestamp_history.hpp"
#include "libtorrent/aux_/numeric_cast.hpp"
namespace libtorrent {
@ -93,7 +94,7 @@ std::uint32_t timestamp_history::add_sample(std::uint32_t sample, bool step)
void timestamp_history::adjust_base(int change)
{
TORRENT_ASSERT(initialized());
m_base += change;
m_base += aux::numeric_cast<std::uint32_t>(change);
// make sure this adjustment sticks by updating all history slots
for (int i = 0; i < history_size; ++i)
{

View File

@ -1720,7 +1720,7 @@ bool utp_socket_impl::send_pkt(int const flags)
// congestion window and the advertised receive window from
// the other end.
if (m_bytes_in_flight + payload_size > std::min(int(m_cwnd >> 16)
, int(m_adv_wnd - m_bytes_in_flight)))
, int(m_adv_wnd) - m_bytes_in_flight))
{
// this means there's not enough room in the send window for
// another packet. We have to hold off sending this data.