From 1f72843fe3aef10d7adf0a67b53ef6d1b2cfa2e4 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Tue, 7 Feb 2017 23:36:13 -0500 Subject: [PATCH] fixing sign-conversion warnings, part 13, minor refactor (#1675) fixing sign-conversion warnings, part 13, minor refactor --- include/libtorrent/pe_crypto.hpp | 3 +- include/libtorrent/peer_connection.hpp | 4 +-- src/http_seed_connection.cpp | 32 ++++++++++---------- src/lazy_bdecode.cpp | 28 +++++++++--------- src/pe_crypto.cpp | 17 ++++++----- src/peer_connection.cpp | 24 +++++++-------- src/storage_utils.cpp | 14 +++++---- src/torrent_handle.cpp | 4 +-- src/torrent_info.cpp | 41 +++++++++++++------------- 9 files changed, 87 insertions(+), 80 deletions(-) diff --git a/include/libtorrent/pe_crypto.hpp b/include/libtorrent/pe_crypto.hpp index 5cd4e81e8..07adb8534 100644 --- a/include/libtorrent/pe_crypto.hpp +++ b/include/libtorrent/pe_crypto.hpp @@ -47,6 +47,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/span.hpp" #include "libtorrent/buffer.hpp" +#include "libtorrent/aux_/array.hpp" #include #include @@ -63,7 +64,7 @@ namespace libtorrent // RC4 state from libtomcrypt struct rc4 { int x, y; - std::array buf; + aux::array buf; }; // TODO: 3 dh_key_exchange should probably move into its own file diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index dce466c25..26f547a8b 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -934,7 +934,7 @@ namespace libtorrent // it just serves as a queue to remember what we've sent, to avoid // re-sending suggests for the same piece // i.e. outgoing suggest pieces - std::vector m_suggest_pieces; + aux::vector m_suggest_pieces; // the pieces we will send to the peer // if requested (regardless of choke state) @@ -952,7 +952,7 @@ namespace libtorrent // pieces that has been suggested to be downloaded from this peer // i.e. incoming suggestions // TODO: 2 this should really be a circular buffer - std::vector m_suggested_pieces; + aux::vector m_suggested_pieces; // the time when this peer last saw a complete copy // of this torrent diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index a3a46da4f..faae45967 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -246,7 +246,8 @@ namespace libtorrent std::tie(payload, protocol) = m_parser.incoming( recv_buffer, parse_error); received_bytes(0, protocol); - bytes_transferred -= protocol; + TORRENT_ASSERT(bytes_transferred >= aux::numeric_cast(protocol)); + bytes_transferred -= aux::numeric_cast(protocol); #if TORRENT_USE_ASSERTS if (payload > front_request.length) payload = front_request.length; #endif @@ -348,7 +349,7 @@ namespace libtorrent m_body_start = m_parser.body_start(); } - recv_buffer = recv_buffer.subspan(m_body_start); + recv_buffer = recv_buffer.subspan(aux::numeric_cast(m_body_start)); // ========================= // === CHUNKED ENCODING === @@ -359,15 +360,15 @@ namespace libtorrent { int header_size = 0; std::int64_t chunk_size = 0; - span chunk_start(recv_buffer.begin() + m_chunk_pos, std::size_t(int(recv_buffer.size()) - m_chunk_pos)); + span chunk_start(recv_buffer.begin() + m_chunk_pos, aux::numeric_cast(int(recv_buffer.size()) - m_chunk_pos)); TORRENT_ASSERT(chunk_start[0] == '\r' || aux::is_hex(chunk_start[0])); bool ret = m_parser.parse_chunk_header(chunk_start, &chunk_size, &header_size); if (!ret) { - TORRENT_ASSERT(bytes_transferred >= size_t(chunk_start.size() - m_partial_chunk_header)); - bytes_transferred -= chunk_start.size() - m_partial_chunk_header; - received_bytes(0, int(chunk_start.size() - m_partial_chunk_header)); + TORRENT_ASSERT(bytes_transferred >= aux::numeric_cast(int(chunk_start.size()) - m_partial_chunk_header)); + bytes_transferred -= aux::numeric_cast(int(chunk_start.size()) - m_partial_chunk_header); + received_bytes(0, int(chunk_start.size()) - m_partial_chunk_header); m_partial_chunk_header = int(chunk_start.size()); if (bytes_transferred == 0) return; break; @@ -379,23 +380,23 @@ namespace libtorrent , "parsed chunk: %" PRId64 " header_size: %d" , chunk_size, header_size); #endif - TORRENT_ASSERT(bytes_transferred >= size_t(header_size - m_partial_chunk_header)); - bytes_transferred -= header_size - m_partial_chunk_header; + TORRENT_ASSERT(bytes_transferred >= aux::numeric_cast(header_size - m_partial_chunk_header)); + bytes_transferred -= aux::numeric_cast(header_size - m_partial_chunk_header); received_bytes(0, header_size - m_partial_chunk_header); m_partial_chunk_header = 0; - TORRENT_ASSERT(chunk_size != 0 || int(chunk_start.size()) <= header_size || chunk_start[header_size] == 'H'); + TORRENT_ASSERT(chunk_size != 0 || int(chunk_start.size()) <= header_size || chunk_start[std::size_t(header_size)] == 'H'); // cut out the chunk header from the receive buffer TORRENT_ASSERT(m_chunk_pos + m_body_start < INT_MAX); m_recv_buffer.cut(header_size, t->block_size() + 1024, int(m_chunk_pos + m_body_start)); recv_buffer = m_recv_buffer.get(); - recv_buffer = recv_buffer.subspan(m_body_start); + recv_buffer = recv_buffer.subspan(aux::numeric_cast(m_body_start)); m_chunk_pos += chunk_size; if (chunk_size == 0) { TORRENT_ASSERT(int(m_recv_buffer.get().size()) < m_chunk_pos + m_body_start + 1 - || m_recv_buffer.get()[int(m_chunk_pos + m_body_start)] == 'H' - || (m_parser.chunked_encoding() && m_recv_buffer.get()[int(m_chunk_pos + m_body_start)] == '\r')); + || m_recv_buffer.get()[aux::numeric_cast(m_chunk_pos + m_body_start)] == 'H' + || (m_parser.chunked_encoding() && m_recv_buffer.get()[aux::numeric_cast(m_chunk_pos + m_body_start)] == '\r')); m_chunk_pos = -1; } } @@ -441,13 +442,14 @@ namespace libtorrent int size_to_cut = m_body_start + front_request.length; TORRENT_ASSERT(int(m_recv_buffer.get().size()) < size_to_cut + 1 - || m_recv_buffer.get()[size_to_cut] == 'H' - || (m_parser.chunked_encoding() && m_recv_buffer.get()[size_to_cut] == '\r')); + || m_recv_buffer.get()[aux::numeric_cast(size_to_cut)] == 'H' + || (m_parser.chunked_encoding() && m_recv_buffer.get()[aux::numeric_cast(size_to_cut)] == '\r')); m_recv_buffer.cut(size_to_cut, t->block_size() + 1024); if (m_response_left == 0) m_chunk_pos = 0; else m_chunk_pos -= front_request.length; - bytes_transferred -= payload; + TORRENT_ASSERT(bytes_transferred >= aux::numeric_cast(payload)); + bytes_transferred -= aux::numeric_cast(payload); m_body_start = 0; if (m_response_left > 0) continue; TORRENT_ASSERT(m_response_left == 0); diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index d9189d076..2bd653c1c 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -256,17 +256,17 @@ namespace libtorrent if (m_data.dict == nullptr) { int capacity = lazy_entry_dict_init; - m_data.dict = new (std::nothrow) lazy_dict_entry[capacity+1]; + m_data.dict = new (std::nothrow) lazy_dict_entry[capacity + 1]; if (m_data.dict == nullptr) return nullptr; m_data.dict[0].val.m_len = capacity; } else if (int(m_size) == this->capacity()) { int capacity = this->capacity() * lazy_entry_grow_factor / 100; - lazy_dict_entry* tmp = new (std::nothrow) lazy_dict_entry[capacity+1]; + lazy_dict_entry* tmp = new (std::nothrow) lazy_dict_entry[capacity + 1]; if (tmp == nullptr) return nullptr; std::memcpy(tmp, m_data.dict, sizeof(lazy_dict_entry) * (m_size + 1)); - for (int i = 0; i < int(m_size); ++i) m_data.dict[i+1].val.release(); + for (int i = 0; i < int(m_size); ++i) m_data.dict[i + 1].val.release(); delete[] m_data.dict; m_data.dict = tmp; @@ -274,7 +274,7 @@ namespace libtorrent } TORRENT_ASSERT(int(m_size) < this->capacity()); - lazy_dict_entry& ret = m_data.dict[1+m_size++]; + lazy_dict_entry& ret = m_data.dict[1 + m_size++]; ret.name = name; return &ret.val; } @@ -300,7 +300,7 @@ namespace libtorrent } } - void lazy_entry::construct_string(char const* start, int length) + void lazy_entry::construct_string(char const* start, int const length) { TORRENT_ASSERT(m_type == none_t); m_type = string_t; @@ -328,11 +328,11 @@ namespace libtorrent } } - std::pair lazy_entry::dict_at(int i) const + std::pair lazy_entry::dict_at(int const i) const { TORRENT_ASSERT(m_type == dict_t); TORRENT_ASSERT(i < int(m_size)); - lazy_dict_entry const& e = m_data.dict[i+1]; + lazy_dict_entry const& e = m_data.dict[i + 1]; return std::make_pair(std::string(e.name, e.val.m_begin - e.name), &e.val); } @@ -425,17 +425,17 @@ namespace libtorrent if (m_data.start == nullptr) { int capacity = lazy_entry_list_init; - m_data.list = new (std::nothrow) lazy_entry[capacity+1]; + m_data.list = new (std::nothrow) lazy_entry[capacity + 1]; if (m_data.list == nullptr) return nullptr; m_data.list[0].m_len = capacity; } else if (int(m_size) == this->capacity()) { int capacity = this->capacity() * lazy_entry_grow_factor / 100; - lazy_entry* tmp = new (std::nothrow) lazy_entry[capacity+1]; + lazy_entry* tmp = new (std::nothrow) lazy_entry[capacity + 1]; if (tmp == nullptr) return nullptr; - std::memcpy(tmp, m_data.list, sizeof(lazy_entry) * (m_size+1)); - for (int i = 0; i < int(m_size); ++i) m_data.list[i+1].release(); + std::memcpy(tmp, m_data.list, sizeof(lazy_entry) * (m_size + 1)); + for (int i = 0; i < int(m_size); ++i) m_data.list[i + 1].release(); delete[] m_data.list; m_data.list = tmp; @@ -559,7 +559,7 @@ namespace libtorrent } } - void print_string(std::string& ret, char const* str, int len, bool single_line) + void print_string(std::string& ret, char const* str, int const len, bool single_line) { bool printable = true; for (int i = 0; i < len; ++i) @@ -576,7 +576,7 @@ namespace libtorrent { ret.append(str, 14); ret += "..."; - ret.append(str + len-14, 14); + ret.append(str + len - 14, 14); } else ret.append(str, len); @@ -604,7 +604,7 @@ namespace libtorrent indent_str[0] = ','; indent_str[1] = '\n'; indent_str[199] = 0; - if (indent < 197 && indent >= 0) indent_str[indent+2] = 0; + if (indent < 197 && indent >= 0) indent_str[indent + 2] = 0; std::string ret; switch (e.type()) { diff --git a/src/pe_crypto.cpp b/src/pe_crypto.cpp index e81a65784..44ddadb19 100644 --- a/src/pe_crypto.cpp +++ b/src/pe_crypto.cpp @@ -75,8 +75,8 @@ namespace libtorrent if (end < begin + 96) { int const len = int(end - begin); - std::memmove(begin + 96 - len, begin, len); - std::memset(begin, 0, 96 - len); + std::memmove(begin + 96 - len, begin, aux::numeric_cast(len)); + std::memset(begin, 0, aux::numeric_cast(96 - len)); } return ret; } @@ -143,7 +143,7 @@ namespace libtorrent if (to_process < size) { new (&bufs[i]) span( - iovec[i].data(), to_process); + iovec[i].data(), aux::numeric_cast(to_process)); to_process = 0; } else @@ -222,7 +222,8 @@ namespace libtorrent std::tie(consume, produce, packet_size) = m_dec_handler->decrypt(wr_buf); TORRENT_ASSERT(packet_size || produce); TORRENT_ASSERT(packet_size >= 0); - bytes_transferred = produce; + TORRENT_ASSERT(produce >= 0); + bytes_transferred = std::size_t(produce); if (packet_size) recv_buffer.crypto_cut(consume, packet_size); } @@ -320,7 +321,7 @@ namespace libtorrent TORRENT_ASSERT(pos); bytes_processed += len; - rc4_encrypt(pos, len, &m_rc4_outgoing); + rc4_encrypt(pos, std::uint32_t(len), &m_rc4_outgoing); } return std::make_tuple(bytes_processed, empty); } @@ -339,7 +340,7 @@ namespace libtorrent TORRENT_ASSERT(pos); bytes_processed += len; - rc4_encrypt(pos, len, &m_rc4_incoming); + rc4_encrypt(pos, std::uint32_t(len), &m_rc4_incoming); } return std::make_tuple(0, bytes_processed, 0); } @@ -351,7 +352,7 @@ namespace libtorrent void rc4_init(const unsigned char* in, unsigned long len, rc4 *state) { size_t const key_size = sizeof(state->buf); - std::array key; + aux::array key; std::uint8_t tmp, *s; int keylen, x, y, j; @@ -371,7 +372,7 @@ void rc4_init(const unsigned char* in, unsigned long len, rc4 *state) /* make RC4 perm and shuffle */ for (x = 0; x < int(key_size); ++x) { - s[x] = std::uint8_t(x); + s[x] = x & 0xff; } for (j = x = y = 0; x < int(key_size); x++) { diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 4c250fd93..6953376d4 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1550,14 +1550,14 @@ namespace libtorrent // the later the suggestion is received, the higher priority we should // ascribe to it, so we need to insert suggestions at the front of the // queue. - if (int(m_suggested_pieces.size()) > m_settings.get_int(settings_pack::max_suggest_pieces)) + if (m_suggested_pieces.end_index() > m_settings.get_int(settings_pack::max_suggest_pieces)) m_suggested_pieces.resize(m_settings.get_int(settings_pack::max_suggest_pieces) - 1); m_suggested_pieces.insert(m_suggested_pieces.begin(), index); #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::info, "SUGGEST_PIECE", "piece: %d added to set: %d" - , static_cast(index), int(m_suggested_pieces.size())); + , static_cast(index), m_suggested_pieces.end_index()); #endif } @@ -2008,9 +2008,9 @@ namespace libtorrent if (should_log(peer_log_alert::incoming_message)) { std::string bitfield_str; - bitfield_str.resize(bits.size()); + bitfield_str.resize(aux::numeric_cast(bits.size())); for (piece_index_t i(0); i != bits.end_index(); ++i) - bitfield_str[static_cast(i)] = bits[i] ? '1' : '0'; + bitfield_str[std::size_t(static_cast(i))] = bits[i] ? '1' : '0'; peer_log(peer_log_alert::incoming_message, "BITFIELD" , "%s", bitfield_str.c_str()); } @@ -3785,9 +3785,9 @@ namespace libtorrent send_suggest(*i); } int const max = m_settings.get_int(settings_pack::max_suggest_pieces); - if (int(m_suggest_pieces.size()) > max) + if (m_suggest_pieces.end_index() > max) { - int const to_erase = int(m_suggest_pieces.size() - max); + int const to_erase = m_suggest_pieces.end_index() - max; m_suggest_pieces.erase(m_suggest_pieces.begin() , m_suggest_pieces.begin() + to_erase); } @@ -3878,7 +3878,7 @@ namespace libtorrent m_counters.inc_stats_counter(counters::num_peers_down_requests); TORRENT_ASSERT(verify_piece(t->to_req(block.block))); - block.send_buffer_offset = m_send_buffer.size(); + block.send_buffer_offset = aux::numeric_cast(m_send_buffer.size()); m_download_queue.push_back(block); m_outstanding_bytes += block_size; #if TORRENT_USE_INVARIANT_CHECKS @@ -3906,7 +3906,7 @@ namespace libtorrent if (m_download_queue.empty()) m_counters.inc_stats_counter(counters::num_peers_down_requests); - block.send_buffer_offset = m_send_buffer.size(); + block.send_buffer_offset = aux::numeric_cast(m_send_buffer.size()); m_download_queue.push_back(block); if (m_queued_time_critical) --m_queued_time_critical; @@ -4482,7 +4482,7 @@ namespace libtorrent #else p.progress = float(p.pieces.count()) / float(p.pieces.size()); #endif - p.progress_ppm = int(std::uint64_t(p.pieces.count()) * 1000000 / p.pieces.size()); + p.progress_ppm = int(std::int64_t(p.pieces.count()) * 1000000 / p.pieces.size()); } p.estimated_reciprocation_rate = m_est_reciprocation_rate; @@ -5677,7 +5677,7 @@ namespace libtorrent int const alloc_buf_size = m_ses.send_buffer_size(); int const buf_size = std::min(alloc_buf_size, size); - std::memcpy(session_buf.get(), buf, buf_size); + std::memcpy(session_buf.get(), buf, aux::numeric_cast(buf_size)); buf += buf_size; size -= buf_size; m_send_buffer.append_buffer(std::move(session_buf), alloc_buf_size, buf_size); @@ -5846,9 +5846,9 @@ namespace libtorrent int sub_transferred = 0; do { sub_transferred = m_recv_buffer.advance_pos(bytes); - on_receive(error, sub_transferred); - bytes -= sub_transferred; TORRENT_ASSERT(sub_transferred > 0); + on_receive(error, std::size_t(sub_transferred)); + bytes -= sub_transferred; if (m_disconnecting) return; } while (bytes > 0 && sub_transferred > 0); diff --git a/src/storage_utils.cpp b/src/storage_utils.cpp index dc4c00963..5f86112b4 100644 --- a/src/storage_utils.cpp +++ b/src/storage_utils.cpp @@ -44,22 +44,24 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { namespace aux { - int copy_bufs(span bufs, int bytes, span target) + int copy_bufs(span bufs, int const bytes, span target) { int size = 0; for (int i = 0;; i++) { - target[i] = bufs[i]; - size += int(bufs[i].iov_len); + std::size_t const idx = std::size_t(i); + target[idx] = bufs[idx]; + size += int(bufs[idx].iov_len); if (size >= bytes) { - target[i].iov_len -= size - bytes; + TORRENT_ASSERT(target[idx].iov_len >= aux::numeric_cast(size - bytes)); + target[idx].iov_len -= aux::numeric_cast(size - bytes); return i + 1; } } } - span advance_bufs(span bufs, int bytes) + span advance_bufs(span bufs, int const bytes) { int size = 0; for (;;) @@ -69,7 +71,7 @@ namespace libtorrent { namespace aux { bufs.front().iov_base = reinterpret_cast(bufs.front().iov_base) + bufs.front().iov_len - (size - bytes); - bufs.front().iov_len = size - bytes; + bufs.front().iov_len = aux::numeric_cast(size - bytes); return bufs; } bufs = bufs.subspan(1); diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 16cfe5974..0d9747ef3 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -611,7 +611,7 @@ namespace libtorrent // forces the torrent to stay loaded while the client holds it torrent_info const& torrent_handle::get_torrent_info() const { - static std::shared_ptr holder[4]; + static aux::array, 4> holder; static int cursor = 0; static std::mutex holder_mutex; @@ -619,7 +619,7 @@ namespace libtorrent std::lock_guard l(holder_mutex); holder[cursor++] = r; - cursor = cursor % (sizeof(holder) / sizeof(holder[0])); + cursor = cursor % holder.end_index();; return *r; } diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 670f87417..35b2ccac3 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/magnet_uri.hpp" #include "libtorrent/announce_entry.hpp" #include "libtorrent/hex.hpp" // to_hex +#include "libtorrent/aux_/numeric_cast.hpp" #ifndef TORRENT_NO_DEPRECATE #include "libtorrent/lazy_entry.hpp" @@ -238,7 +239,7 @@ namespace libtorrent { // 2 bytes if (element.size() - i < 2 - || (element[i+1] & 0xc0) != 0x80) + || (element[i + 1] & 0xc0) != 0x80) { path += '_'; last_len = 1; @@ -261,8 +262,8 @@ namespace libtorrent { // 3 bytes if (element.size() - i < 3 - || (element[i+1] & 0xc0) != 0x80 - || (element[i+2] & 0xc0) != 0x80 + || (element[i + 1] & 0xc0) != 0x80 + || (element[i + 2] & 0xc0) != 0x80 ) { path += '_'; @@ -335,7 +336,7 @@ namespace libtorrent for (int j = int(element.size()) - 1; j > std::max(int(element.size()) - 10, int(i)); --j) { - if (element[j] != '.') continue; + if (element[aux::numeric_cast(j)] != '.') continue; dot = j; break; } @@ -470,7 +471,7 @@ namespace libtorrent if (p && p.list_size() > 0) { - std::size_t const preallocate = path.size() + path_length(p, ec); + std::size_t const preallocate = path.size() + std::size_t(path_length(p, ec)); if (ec) return false; path.reserve(preallocate); @@ -515,7 +516,7 @@ namespace libtorrent { if (bdecode_node s_p = dict.dict_find_list("symlink path")) { - int const preallocate = path_length(s_p, ec); + std::size_t const preallocate = std::size_t(path_length(s_p, ec)); if (ec) return false; symlink_path.reserve(preallocate); for (int i = 0, end(s_p.list_size()); i < end; ++i) @@ -531,8 +532,8 @@ namespace libtorrent } if (filename_len > int(path.length()) - || path.compare(path.size() - filename_len, filename_len, filename - , filename_len) != 0) + || path.compare(path.size() - std::size_t(filename_len), std::size_t(filename_len), filename + , std::size_t(filename_len)) != 0) { // if the filename was sanitized and differ, clear it to just use path filename = nullptr; @@ -549,7 +550,7 @@ namespace libtorrent std::size_t operator()(std::string const& s) const { char const* s1 = s.c_str(); - size_t ret = 5381; + std::size_t ret = 5381; int c; for (;;) @@ -557,7 +558,7 @@ namespace libtorrent c = *s1++; if (c == 0) break; - ret = (ret * 33) ^ to_lower(char(c)); + ret = (ret * 33) ^ std::size_t(to_lower(char(c))); } return ret; @@ -659,7 +660,7 @@ namespace libtorrent TORRENT_ASSERT(m_piece_hashes); m_info_section.reset(new char[m_info_section_size]); - std::memcpy(m_info_section.get(), t.m_info_section.get(), m_info_section_size); + std::memcpy(m_info_section.get(), t.m_info_section.get(), aux::numeric_cast(m_info_section_size)); ptrdiff_t offset = m_info_section.get() - t.m_info_section.get(); @@ -722,7 +723,7 @@ namespace libtorrent std::unordered_set files; std::vector const& paths = m_files.paths(); - files.reserve(paths.size() + m_files.num_files()); + files.reserve(paths.size() + aux::numeric_cast(m_files.num_files())); // insert all directories first, to make sure no files // are allowed to collied with them @@ -1053,9 +1054,9 @@ namespace libtorrent // copy the info section m_info_section_size = int(section.size()); m_info_section.reset(new char[m_info_section_size]); - std::memcpy(m_info_section.get(), section.data(), m_info_section_size); + std::memcpy(m_info_section.get(), section.data(), aux::numeric_cast(m_info_section_size)); TORRENT_ASSERT(section[0] == 'd'); - TORRENT_ASSERT(section[m_info_section_size - 1] == 'e'); + TORRENT_ASSERT(section[aux::numeric_cast(m_info_section_size - 1)] == 'e'); // when translating a pointer that points into the 'info' tree's // backing buffer, into a pointer to our copy of the info section, @@ -1157,7 +1158,7 @@ namespace libtorrent m_files.set_piece_length(0); return false; } - if (files.num_pieces() >= std::numeric_limits::max()/2) + if (files.num_pieces() >= std::numeric_limits::max() / 2) { ec = errors::too_many_pieces_in_torrent; // mark the torrent as invalid @@ -1168,7 +1169,7 @@ namespace libtorrent int const num_nodes = merkle_num_nodes(num_leafs); m_merkle_first_leaf = num_nodes - num_leafs; m_merkle_tree.resize(num_nodes); - std::memset(&m_merkle_tree[0], 0, num_nodes * 20); + std::memset(m_merkle_tree.data(), 0, aux::numeric_cast(num_nodes * 20)); m_merkle_tree[0].assign(root_hash.string_ptr()); } @@ -1293,7 +1294,7 @@ namespace libtorrent ret[sibling] = m_merkle_tree[sibling]; // we cannot build the tree path if one // of the nodes in the tree is missing - TORRENT_ASSERT(m_merkle_tree[sibling] != sha1_hash(nullptr)); + TORRENT_ASSERT(!m_merkle_tree[sibling].is_all_zeros()); n = parent; } return ret; @@ -1361,7 +1362,7 @@ namespace libtorrent if (str.type() != bdecode_node::string_t) continue; m_owned_collections.push_back(std::string(str.string_ptr() - , str.string_length())); + , aux::numeric_cast(str.string_length()))); } } #endif // TORRENT_DISABLE_MUTABLE_TORRENTS @@ -1442,7 +1443,7 @@ namespace libtorrent std::int64_t cd = torrent_file.dict_find_int_value("creation date", -1); if (cd >= 0) { - m_creation_date = long(cd); + m_creation_date = std::time_t(cd); } // if there are any url-seeds, extract them @@ -1606,7 +1607,7 @@ namespace libtorrent ret.reserve(m_collections.size() + m_owned_collections.size()); for (auto const& c : m_collections) - ret.push_back(std::string(c.first, c.second)); + ret.push_back(std::string(c.first, aux::numeric_cast(c.second))); for (auto const& c : m_owned_collections) ret.push_back(c);