fixing shorten-64-to-32 warnings, part 1

This commit is contained in:
Alden Torres 2016-12-04 20:15:49 -05:00 committed by Arvid Norberg
parent b9169609df
commit 37cbdc5b37
11 changed files with 54 additions and 50 deletions

View File

@ -172,24 +172,26 @@ struct bdecode_token
max_header = (1 << 3) - 1
};
bdecode_token(std::uint32_t off, bdecode_token::type_t t)
: offset(off)
bdecode_token(std::ptrdiff_t off, bdecode_token::type_t t)
: offset(std::uint32_t(off))
, type(t)
, next_item(0)
, header(0)
{
TORRENT_ASSERT(off >= 0);
TORRENT_ASSERT(off <= max_offset);
TORRENT_ASSERT(t >= 0 && t <= end);
}
bdecode_token(std::uint32_t off, std::uint32_t next
bdecode_token(std::ptrdiff_t off, std::uint32_t next
, bdecode_token::type_t t, std::uint8_t header_size = 0)
: offset(off)
: offset(std::uint32_t(off))
, type(t)
, next_item(next)
, header(type == string ? std::uint32_t(header_size - 2) : 0)
{
TORRENT_ASSERT(type != string || header_size >= 2);
TORRENT_ASSERT(off >= 0);
TORRENT_ASSERT(off <= max_offset);
TORRENT_ASSERT(next <= max_next_item);
// the string has 2 implied header bytes, to allow for longer prefixes

View File

@ -422,7 +422,8 @@ namespace libtorrent
if (err) return entry();
return e;
}
template<class InIt> entry bdecode(InIt start, InIt end, int& len)
template<class InIt> entry bdecode(InIt start, InIt end
, typename std::iterator_traits<InIt>::difference_type& len)
{
entry e;
bool err = false;

View File

@ -88,7 +88,7 @@ struct average_accumulator
{
average_accumulator() {}
void add_sample(int s)
void add_sample(std::int64_t s)
{
++m_num_samples;
m_sample_sum += s;

View File

@ -377,7 +377,7 @@ namespace libtorrent
void update_transaction_id(
std::shared_ptr<udp_tracker_connection> c
, std::uint64_t tid);
, std::uint32_t tid);
aux::session_settings const& settings() const { return m_settings; }
resolver_interface& host_resolver() { return m_host_resolver; }

View File

@ -170,7 +170,7 @@ namespace libtorrent
// make the two surrounding pages non-readable and -writable
mprotect(block - page, page, PROT_READ | PROT_WRITE);
alloc_header* h = reinterpret_cast<alloc_header*>(block - page);
const int num_pages = (h->size + (page-1)) / page + 2;
const int num_pages = int((h->size + (page-1)) / page + 2);
TORRENT_ASSERT(h->magic == 0x1337);
mprotect(block + (num_pages-2) * page, page, PROT_READ | PROT_WRITE);
// std::fprintf(stderr, "free: %p head: %p tail: %p size: %d\n", block, block - page, block + h->size, int(h->size));

View File

@ -72,10 +72,10 @@ namespace libtorrent
#ifndef TORRENT_NO_DEPRECATE
int announce_entry::next_announce_in() const
{ return total_seconds(next_announce - aux::time_now()); }
{ return int(total_seconds(next_announce - aux::time_now())); }
int announce_entry::min_announce_in() const
{ return total_seconds(min_announce - aux::time_now()); }
{ return int(total_seconds(min_announce - aux::time_now())); }
#endif
void announce_entry::reset()
@ -91,7 +91,7 @@ namespace libtorrent
// the exponential back-off ends up being:
// 7, 15, 27, 45, 95, 127, 165, ... seconds
// with the default tracker_backoff of 250
int const tracker_backoff_seconds = total_seconds(tracker_backoff);
int const tracker_backoff_seconds = int(total_seconds(tracker_backoff));
int const delay = std::max(std::min(tracker_retry_delay_min + int(fails) * int(fails)
* tracker_retry_delay_min * tracker_backoff_seconds / 100
, int(tracker_retry_delay_max)), retry_interval);

View File

@ -198,7 +198,7 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth
nullptr,
&SymFunctionTableAccess64,
&SymGetModuleBase64,
nullptr) && size < stack.size())
nullptr) && size < int(stack.size()))
{
stack[size++] = reinterpret_cast<void*>(stack_frame.AddrPC.Offset);
}

View File

@ -760,7 +760,7 @@ namespace libtorrent
if (ret.m_tokens.size() - top > bdecode_token::max_next_item)
TORRENT_FAIL_BDECODE(bdecode_errors::limit_exceeded);
ret.m_tokens[top].next_item = ret.m_tokens.size() - top;
ret.m_tokens[top].next_item = std::uint32_t(ret.m_tokens.size() - top);
// and pop it from the stack.
--sp;
@ -839,7 +839,7 @@ done:
int const top = stack[sp].token;
TORRENT_ASSERT(ret.m_tokens.size() - top <= bdecode_token::max_next_item);
ret.m_tokens[top].next_item = ret.m_tokens.size() - top;
ret.m_tokens[top].next_item = std::uint32_t(ret.m_tokens.size() - top);
ret.m_tokens.push_back(bdecode_token(start - orig_start, 1, bdecode_token::end));
}
@ -848,7 +848,7 @@ done:
ret.m_token_idx = 0;
ret.m_buffer = orig_start;
ret.m_buffer_size = start - orig_start;
ret.m_buffer_size = int(start - orig_start);
ret.m_root_tokens = &ret.m_tokens[0];
return ec ? -1 : 0;

View File

@ -658,7 +658,7 @@ namespace libtorrent
if (!failed)
{
TORRENT_PIECE_ASSERT(!error, pe);
std::uint32_t write_time = total_microseconds(clock_type::now() - start_time);
std::int64_t write_time = total_microseconds(clock_type::now() - start_time);
m_write_time.add_sample(write_time / num_blocks);
m_stats_counters.inc_stats_counter(counters::num_blocks_written, num_blocks);
@ -1202,10 +1202,11 @@ namespace libtorrent
, j->piece, j->d.io.offset, file_flags, j->error);
TORRENT_ASSERT(ret >= 0 || j->error.ec);
TORRENT_UNUSED(ret);
if (!j->error.ec)
{
std::uint32_t read_time = total_microseconds(clock_type::now() - start_time);
std::int64_t read_time = total_microseconds(clock_type::now() - start_time);
m_read_time.add_sample(read_time);
m_stats_counters.inc_stats_counter(counters::num_read_back);
@ -1274,11 +1275,11 @@ namespace libtorrent
time_point start_time = clock_type::now();
ret = j->storage->readv(iov
, j->piece, adjusted_offset, file_flags, j->error);
, j->piece, int(adjusted_offset), file_flags, j->error);
if (!j->error.ec)
{
std::uint32_t const read_time = total_microseconds(clock_type::now() - start_time);
std::int64_t const read_time = total_microseconds(clock_type::now() - start_time);
m_read_time.add_sample(read_time / iov_len);
m_stats_counters.inc_stats_counter(counters::num_blocks_read, iov_len);
@ -1441,7 +1442,7 @@ namespace libtorrent
if (!j->error.ec)
{
std::uint32_t write_time = total_microseconds(clock_type::now() - start_time);
std::int64_t write_time = total_microseconds(clock_type::now() - start_time);
m_write_time.add_sample(write_time);
m_stats_counters.inc_stats_counter(counters::num_blocks_written);
@ -2030,7 +2031,7 @@ namespace libtorrent
offset += size;
}
std::uint64_t hash_time = total_microseconds(clock_type::now() - start_time);
std::int64_t hash_time = total_microseconds(clock_type::now() - start_time);
l.lock();
@ -2121,7 +2122,7 @@ namespace libtorrent
if (!j->error.ec)
{
std::uint32_t const read_time = total_microseconds(clock_type::now() - start_time);
std::int64_t const read_time = total_microseconds(clock_type::now() - start_time);
m_read_time.add_sample(read_time);
m_stats_counters.inc_stats_counter(counters::num_blocks_read);
@ -2331,7 +2332,7 @@ namespace libtorrent
if (!j->error.ec)
{
std::uint32_t read_time = total_microseconds(clock_type::now() - start_time);
std::int64_t read_time = total_microseconds(clock_type::now() - start_time);
m_read_time.add_sample(read_time);
m_stats_counters.inc_stats_counter(counters::num_read_back);
@ -2572,41 +2573,41 @@ namespace libtorrent
#ifndef TORRENT_NO_DEPRECATE
ret->total_used_buffers = m_disk_cache.in_use();
ret->blocks_read_hit = m_stats_counters[counters::num_blocks_cache_hits];
ret->blocks_read = m_stats_counters[counters::num_blocks_read];
ret->blocks_written = m_stats_counters[counters::num_blocks_written];
ret->writes = m_stats_counters[counters::num_write_ops];
ret->reads = m_stats_counters[counters::num_read_ops];
ret->blocks_read_hit = int(m_stats_counters[counters::num_blocks_cache_hits]);
ret->blocks_read = int(m_stats_counters[counters::num_blocks_read]);
ret->blocks_written = int(m_stats_counters[counters::num_blocks_written]);
ret->writes = int(m_stats_counters[counters::num_write_ops]);
ret->reads = int(m_stats_counters[counters::num_read_ops]);
int num_read_jobs = (std::max)(std::int64_t(1)
, m_stats_counters[counters::num_read_ops]);
int num_write_jobs = (std::max)(std::int64_t(1)
, m_stats_counters[counters::num_write_ops]);
int num_hash_jobs = (std::max)(std::int64_t(1)
, m_stats_counters[counters::num_blocks_hashed]);
int num_read_jobs = int((std::max)(std::int64_t(1)
, m_stats_counters[counters::num_read_ops]));
int num_write_jobs = int((std::max)(std::int64_t(1)
, m_stats_counters[counters::num_write_ops]));
int num_hash_jobs = int((std::max)(std::int64_t(1)
, m_stats_counters[counters::num_blocks_hashed]));
ret->average_read_time = m_stats_counters[counters::disk_read_time] / num_read_jobs;
ret->average_write_time = m_stats_counters[counters::disk_write_time] / num_write_jobs;
ret->average_hash_time = m_stats_counters[counters::disk_hash_time] / num_hash_jobs;
ret->average_job_time = m_stats_counters[counters::disk_job_time]
/ (num_read_jobs + num_write_jobs + num_hash_jobs);
ret->cumulative_job_time = m_stats_counters[counters::disk_job_time];
ret->cumulative_read_time = m_stats_counters[counters::disk_read_time];
ret->cumulative_write_time = m_stats_counters[counters::disk_write_time];
ret->cumulative_hash_time = m_stats_counters[counters::disk_hash_time];
ret->total_read_back = m_stats_counters[counters::num_read_back];
ret->average_read_time = int(m_stats_counters[counters::disk_read_time] / num_read_jobs);
ret->average_write_time = int(m_stats_counters[counters::disk_write_time] / num_write_jobs);
ret->average_hash_time = int(m_stats_counters[counters::disk_hash_time] / num_hash_jobs);
ret->average_job_time = int(m_stats_counters[counters::disk_job_time]
/ (num_read_jobs + num_write_jobs + num_hash_jobs));
ret->cumulative_job_time = int(m_stats_counters[counters::disk_job_time]);
ret->cumulative_read_time = int(m_stats_counters[counters::disk_read_time]);
ret->cumulative_write_time = int(m_stats_counters[counters::disk_write_time]);
ret->cumulative_hash_time = int(m_stats_counters[counters::disk_hash_time]);
ret->total_read_back = int(m_stats_counters[counters::num_read_back]);
ret->blocked_jobs = m_stats_counters[counters::blocked_disk_jobs];
ret->blocked_jobs = int(m_stats_counters[counters::blocked_disk_jobs]);
ret->num_jobs = jobs_in_use();
ret->num_read_jobs = read_jobs_in_use();
ret->read_queue_size = read_jobs_in_use();
ret->num_write_jobs = write_jobs_in_use();
ret->pending_jobs = m_stats_counters[counters::num_running_disk_jobs];
ret->num_writing_threads = m_stats_counters[counters::num_writing_threads];
ret->pending_jobs = int(m_stats_counters[counters::num_running_disk_jobs]);
ret->num_writing_threads = int(m_stats_counters[counters::num_writing_threads]);
for (int i = 0; i < disk_io_job::num_job_ids; ++i)
ret->num_fence_jobs[i] = m_stats_counters[counters::num_fenced_read + i];
ret->num_fence_jobs[i] = int(m_stats_counters[counters::num_fenced_read + i]);
m_disk_cache.get_stats(ret);

View File

@ -260,7 +260,7 @@ namespace libtorrent
void tracker_manager::update_transaction_id(
std::shared_ptr<udp_tracker_connection> c
, std::uint64_t tid)
, std::uint32_t tid)
{
TORRENT_ASSERT(is_single_thread());
m_udp_conns.erase(c->transaction_id());

View File

@ -304,7 +304,7 @@ namespace libtorrent { namespace
if (!m_pc.packet_finished()) return true;
int len;
std::ptrdiff_t len;
entry msg = bdecode(body.begin(), body.end(), len);
if (msg.type() != entry::dictionary_t)
{