From 37cbdc5b37e08d53317a04ceda6f2b41a240a20b Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Sun, 4 Dec 2016 20:15:49 -0500 Subject: [PATCH] fixing shorten-64-to-32 warnings, part 1 --- include/libtorrent/bdecode.hpp | 10 ++-- include/libtorrent/bencode.hpp | 3 +- include/libtorrent/sliding_average.hpp | 2 +- include/libtorrent/tracker_manager.hpp | 2 +- src/allocator.cpp | 2 +- src/announce_entry.cpp | 6 +-- src/assert.cpp | 2 +- src/bdecode.cpp | 6 +-- src/disk_io_thread.cpp | 67 +++++++++++++------------- src/tracker_manager.cpp | 2 +- src/ut_metadata.cpp | 2 +- 11 files changed, 54 insertions(+), 50 deletions(-) diff --git a/include/libtorrent/bdecode.hpp b/include/libtorrent/bdecode.hpp index 4c3d724cc..8150ba7f0 100644 --- a/include/libtorrent/bdecode.hpp +++ b/include/libtorrent/bdecode.hpp @@ -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 diff --git a/include/libtorrent/bencode.hpp b/include/libtorrent/bencode.hpp index 618342d52..926ddaaa7 100644 --- a/include/libtorrent/bencode.hpp +++ b/include/libtorrent/bencode.hpp @@ -422,7 +422,8 @@ namespace libtorrent if (err) return entry(); return e; } - template entry bdecode(InIt start, InIt end, int& len) + template entry bdecode(InIt start, InIt end + , typename std::iterator_traits::difference_type& len) { entry e; bool err = false; diff --git a/include/libtorrent/sliding_average.hpp b/include/libtorrent/sliding_average.hpp index 2b32d4ffc..7ea6243b8 100644 --- a/include/libtorrent/sliding_average.hpp +++ b/include/libtorrent/sliding_average.hpp @@ -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; diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 76dcb909e..0506bbad9 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -377,7 +377,7 @@ namespace libtorrent void update_transaction_id( std::shared_ptr 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; } diff --git a/src/allocator.cpp b/src/allocator.cpp index 4bb01ae08..8b5386411 100644 --- a/src/allocator.cpp +++ b/src/allocator.cpp @@ -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(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)); diff --git a/src/announce_entry.cpp b/src/announce_entry.cpp index d8e9937e1..e0c64ee83 100644 --- a/src/announce_entry.cpp +++ b/src/announce_entry.cpp @@ -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); diff --git a/src/assert.cpp b/src/assert.cpp index c4832aa3a..eaa340d64 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -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(stack_frame.AddrPC.Offset); } diff --git a/src/bdecode.cpp b/src/bdecode.cpp index 6a67b1252..43a231a48 100644 --- a/src/bdecode.cpp +++ b/src/bdecode.cpp @@ -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; diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 381b051ce..7719d480c 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -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); diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index 73c6f7814..a50f973fe 100644 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -260,7 +260,7 @@ namespace libtorrent void tracker_manager::update_transaction_id( std::shared_ptr c - , std::uint64_t tid) + , std::uint32_t tid) { TORRENT_ASSERT(is_single_thread()); m_udp_conns.erase(c->transaction_id()); diff --git a/src/ut_metadata.cpp b/src/ut_metadata.cpp index d61179ddc..33a559423 100644 --- a/src/ut_metadata.cpp +++ b/src/ut_metadata.cpp @@ -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) {