From 7621be6df1562af763da1bad806d4498a7683f37 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 16 May 2018 10:06:33 -0400 Subject: [PATCH] fixed signed/unsigned warnings with latest version of Xcode clang (#3032) --- src/bitfield.cpp | 2 +- src/block_cache.cpp | 2 +- src/kademlia/dht_storage.cpp | 2 +- src/lazy_bdecode.cpp | 4 ++-- src/part_file.cpp | 2 +- src/torrent.cpp | 2 +- src/torrent_info.cpp | 4 ++-- src/ut_metadata.cpp | 4 ++-- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/bitfield.cpp b/src/bitfield.cpp index de0cb03b4..5d81b2201 100644 --- a/src/bitfield.cpp +++ b/src/bitfield.cpp @@ -170,7 +170,7 @@ namespace libtorrent { int const cur_size_words = num_words(); if (cur_size_words != new_size_words) { - aux::unique_ptr b(new std::uint32_t[new_size_words + 1]); + aux::unique_ptr b(new std::uint32_t[std::size_t(new_size_words + 1)]); #ifdef BOOST_NO_EXCEPTIONS if (b == nullptr) std::terminate(); #endif diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 53fc73de0..63d20ef6b 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -616,7 +616,7 @@ cached_piece_entry* block_cache::allocate_piece(disk_io_job const* j, std::uint1 pe.expire = aux::time_now(); pe.blocks_in_piece = aux::numeric_cast(blocks_in_piece); - pe.blocks.reset(new (std::nothrow) cached_block_entry[blocks_in_piece]); + pe.blocks.reset(new (std::nothrow) cached_block_entry[std::size_t(blocks_in_piece)]); if (!pe.blocks) return nullptr; p = const_cast(&*m_pieces.insert(std::move(pe)).first); diff --git a/src/kademlia/dht_storage.cpp b/src/kademlia/dht_storage.cpp index c42cdcd07..a885c3656 100644 --- a/src/kademlia/dht_storage.cpp +++ b/src/kademlia/dht_storage.cpp @@ -112,7 +112,7 @@ namespace { int const size = int(buf.size()); if (item.size != size) { - item.value.reset(new char[size]); + item.value.reset(new char[std::size_t(size)]); item.size = size; } std::memcpy(item.value.get(), buf.data(), buf.size()); diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index aef84cbff..62f0ed19c 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -265,7 +265,7 @@ namespace { } else if (int(m_size) == this->capacity()) { - int const capacity = this->capacity() * lazy_entry_grow_factor / 100; + std::size_t const capacity = std::size_t(this->capacity()) * lazy_entry_grow_factor / 100; auto* tmp = new (std::nothrow) lazy_dict_entry[capacity + 1]; if (tmp == nullptr) return nullptr; std::move(m_data.dict, m_data.dict + m_size + 1, tmp); @@ -435,7 +435,7 @@ namespace { } else if (int(m_size) == this->capacity()) { - int const capacity = this->capacity() * lazy_entry_grow_factor / 100; + std::size_t const capacity = std::size_t(this->capacity()) * lazy_entry_grow_factor / 100; lazy_entry* tmp = new (std::nothrow) lazy_entry[capacity + 1]; if (tmp == nullptr) return nullptr; std::move(m_data.list, m_data.list + m_size + 1, tmp); diff --git a/src/part_file.cpp b/src/part_file.cpp index 4f6cb1d33..d9500e9d8 100644 --- a/src/part_file.cpp +++ b/src/part_file.cpp @@ -304,7 +304,7 @@ namespace libtorrent { open_file(open_mode::read_only, ec); if (ec) return; - if (!buf) buf.reset(new char[m_piece_size]); + if (!buf) buf.reset(new char[std::size_t(m_piece_size)]); std::int64_t const slot_offset = std::int64_t(m_header_size) + std::int64_t(static_cast(slot)) * m_piece_size; diff --git a/src/torrent.cpp b/src/torrent.cpp index c7050d677..8b059be89 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -852,7 +852,7 @@ bool is_downloading_state(int const st) } std::shared_ptr rp = std::make_shared(); - rp->piece_data.reset(new (std::nothrow) char[piece_size]); + rp->piece_data.reset(new (std::nothrow) char[std::size_t(piece_size)]); if (!rp->piece_data) { m_ses.alerts().emplace_alert( diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index d043c6d12..53f866293 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -576,7 +576,7 @@ namespace { if (m_info_section_size == 0) return; TORRENT_ASSERT(m_piece_hashes); - m_info_section.reset(new char[m_info_section_size]); + m_info_section.reset(new char[aux::numeric_cast(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(); @@ -946,7 +946,7 @@ namespace { // copy the info section m_info_section_size = int(section.size()); - m_info_section.reset(new char[m_info_section_size]); + m_info_section.reset(new char[aux::numeric_cast(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[aux::numeric_cast(m_info_section_size - 1)] == 'e'); diff --git a/src/ut_metadata.cpp b/src/ut_metadata.cpp index b5e1ab59f..202c3e303 100644 --- a/src/ut_metadata.cpp +++ b/src/ut_metadata.cpp @@ -145,7 +145,7 @@ namespace libtorrent {namespace { { if (m_metadata_size > 0 || size <= 0 || size > 4 * 1024 * 1024) return; m_metadata_size = size; - m_metadata.reset(new char[size]); + m_metadata.reset(new char[std::size_t(size)]); m_requested_metadata.resize(div_round_up(size, 16 * 1024)); } @@ -550,7 +550,7 @@ namespace libtorrent {namespace { return false; } - m_metadata.reset(new char[total_size]); + m_metadata.reset(new char[std::size_t(total_size)]); m_requested_metadata.resize(div_round_up(total_size, 16 * 1024)); m_metadata_size = total_size; }