diff --git a/include/libtorrent/ConvertUTF.h b/include/libtorrent/ConvertUTF.h index e95a5cdea..f8b14ddd2 100644 --- a/include/libtorrent/ConvertUTF.h +++ b/include/libtorrent/ConvertUTF.h @@ -114,11 +114,11 @@ typedef uint8_t UTF8; typedef unsigned char Boolean; /* 0 or 1 */ /* Some fundamental constants */ -#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD -#define UNI_MAX_BMP (UTF32)0x0000FFFF -#define UNI_MAX_UTF16 (UTF32)0x0010FFFF -#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF -#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF +#define UNI_REPLACEMENT_CHAR UTF32(0x0000FFFD) +#define UNI_MAX_BMP UTF32(0x0000FFFF) +#define UNI_MAX_UTF16 UTF32(0x0010FFFF) +#define UNI_MAX_UTF32 UTF32(0x7FFFFFFF) +#define UNI_MAX_LEGAL_UTF32 UTF32(0x0010FFFF) typedef enum { conversionOK, /* conversion successful */ diff --git a/src/lt_trackers.cpp b/src/lt_trackers.cpp index c333173f3..78f9abc15 100644 --- a/src/lt_trackers.cpp +++ b/src/lt_trackers.cpp @@ -237,15 +237,15 @@ namespace libtorrent { namespace if (need_encoding(e.url.c_str(), e.url.size())) continue; // ignore invalid URLs - error_code ec; + error_code err; std::string protocol; std::string auth; std::string hostname; int port; std::string path; boost::tie(protocol, auth, hostname, port, path) - = parse_url_components(e.url, ec); - if (ec) continue; + = parse_url_components(e.url, err); + if (err) continue; // ignore unknown protocols if (protocol != "udp" && protocol != "http" && protocol != "https") @@ -273,7 +273,8 @@ namespace libtorrent { namespace virtual void tick() { - if (!m_message_index) return; // no handshake yet + // no handshake yet + if (!m_message_index) return; if (++m_2_minutes <= 120) return; m_2_minutes = 0; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 2db2abbbb..9e59f100a 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4668,8 +4668,8 @@ retry: { torrent_info::nodes_t const& nodes = params.ti->nodes(); std::for_each(nodes.begin(), nodes.end(), boost::bind( - (void(dht::dht_tracker::*)(std::pair const&)) - &dht::dht_tracker::add_node + static_cast const&)>( + &dht::dht_tracker::add_node) , boost::ref(m_dht), _1)); } #endif @@ -6515,7 +6515,7 @@ retry: char buf[1024]; vsnprintf(buf, sizeof(buf), fmt, v); va_end(v); - m_alerts.emplace_alert((dht_log_alert::dht_module_t)m, buf); + m_alerts.emplace_alert(static_cast(m), buf); } void session_impl::log_packet(message_direction_t dir, char const* pkt, int len diff --git a/src/storage.cpp b/src/storage.cpp index da782f6f6..5cb57a314 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -149,7 +149,7 @@ namespace libtorrent size += bufs->iov_len; if (size >= bytes) { - ((char*&)bufs->iov_base) += bufs->iov_len - (size - bytes); + reinterpret_cast(bufs->iov_base) += bufs->iov_len - (size - bytes); bufs->iov_len = size - bytes; return; } @@ -720,7 +720,7 @@ namespace libtorrent TORRENT_ASSERT(slot >= 0); TORRENT_ASSERT(slot < files().num_pieces()); - boost::int64_t file_offset = (boost::int64_t)slot * files().piece_length(); + boost::int64_t file_offset = boost::int64_t(slot) * files().piece_length(); int file_index = 0; for (;;) @@ -1064,8 +1064,8 @@ namespace libtorrent else { // ignore errors when removing - error_code e; - remove_all(old_path, e); + error_code ignore; + remove_all(old_path, ignore); } break; } @@ -1270,8 +1270,8 @@ namespace libtorrent write_access_log(adjusted_offset, handle->file_id(), op_start | flags, clock_type::now()); #endif - bytes_transferred = (int)((*handle).*op.op)(adjusted_offset - , tmp_bufs, num_tmp_bufs, e, op.mode); + bytes_transferred = int(((*handle).*op.op)(adjusted_offset + , tmp_bufs, num_tmp_bufs, e, op.mode)); // we either get an error or 0 or more bytes read TORRENT_ASSERT(e || bytes_transferred >= 0); @@ -1431,6 +1431,7 @@ namespace libtorrent storage_interface* disabled_storage_constructor(storage_params const& params) { + TORRENT_UNUSED(params); return new disabled_storage; } diff --git a/src/torrent.cpp b/src/torrent.cpp index af4b5189c..09f1e92e0 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -8380,7 +8380,7 @@ namespace libtorrent TORRENT_ASSERT(index >= 0); TORRENT_ASSERT(index < int(m_trackers.size())); - if (index >= (int)m_trackers.size()) return -1; + if (index >= int(m_trackers.size())) return -1; while (index > 0 && m_trackers[index].tier == m_trackers[index-1].tier) { @@ -8399,7 +8399,7 @@ namespace libtorrent TORRENT_ASSERT(index >= 0); TORRENT_ASSERT(index < int(m_trackers.size())); - if (index >= (int)m_trackers.size()) return -1; + if (index >= int(m_trackers.size())) return -1; while (index < int(m_trackers.size()) - 1 && m_trackers[index].tier == m_trackers[index + 1].tier) { @@ -11318,7 +11318,6 @@ namespace libtorrent return; } - int num_files = m_torrent_file->num_files(); // if this is the first time the client asks for file progress. // allocate it and make sure it's up to date @@ -11454,7 +11453,7 @@ namespace libtorrent if (m_ses.alerts().should_post()) { m_ses.alerts().emplace_alert(get_handle() - , s, (torrent_status::state_t)m_state); + , s, static_cast(m_state)); } if (s == torrent_status::finished @@ -11600,7 +11599,7 @@ namespace libtorrent st->time_since_download = m_last_download == (std::numeric_limits::min)() ? -1 : clamped_subtract(m_ses.session_time(), m_last_download); - st->storage_mode = (storage_mode_t)m_storage_mode; + st->storage_mode = static_cast(m_storage_mode); st->num_complete = (m_complete == 0xffffff) ? -1 : m_complete; st->num_incomplete = (m_incomplete == 0xffffff) ? -1 : m_incomplete; @@ -11680,7 +11679,7 @@ namespace libtorrent st->need_save_resume = need_save_resume_data(); st->ip_filter_applies = m_apply_ip_filter; - st->state = (torrent_status::state_t)m_state; + st->state = static_cast(m_state); #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS if (st->state == torrent_status::finished diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 2c9c3a96c..b5c3b184a 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -588,7 +588,7 @@ namespace libtorrent ec = errors::metadata_too_large; return -2; } - v.resize((unsigned int)s); + v.resize(std::size_t(s)); if (s == 0) return 0; file::iovec_t b = {&v[0], size_t(s) }; boost::int64_t read = f.readv(0, &b, 1, ec); @@ -1266,8 +1266,8 @@ namespace libtorrent if (name.empty()) name = to_hex(m_info_hash.to_string()); // extract file list - bdecode_node i = info.dict_find_list("files"); - if (!i) + bdecode_node files_node = info.dict_find_list("files"); + if (!files_node) { // if there's no list of files, there has to be a length // field. @@ -1278,7 +1278,7 @@ namespace libtorrent } else { - if (!extract_files(i, files, name, info_ptr_diff, ec)) + if (!extract_files(files_node, files, name, info_ptr_diff, ec)) return false; m_multifile = true; } @@ -1521,13 +1521,13 @@ namespace libtorrent #endif // TORRENT_DISABLE_MUTABLE_TORRENTS // extract the url of the tracker - bdecode_node i = torrent_file.dict_find_list("announce-list"); - if (i) + bdecode_node announce_node = torrent_file.dict_find_list("announce-list"); + if (announce_node) { - m_urls.reserve(i.list_size()); - for (int j = 0, end(i.list_size()); j < end; ++j) + m_urls.reserve(announce_node.list_size()); + for (int j = 0, end(announce_node.list_size()); j < end; ++j) { - bdecode_node tier = i.list_at(j); + bdecode_node tier = announce_node.list_at(j); if (tier.type() != bdecode_node::list_t) continue; for (int k = 0, end(tier.list_size()); k < end; ++k) { @@ -1562,7 +1562,6 @@ namespace libtorrent std::random_shuffle(start, stop); } } - if (m_urls.empty()) { diff --git a/src/torrent_peer_allocator.cpp b/src/torrent_peer_allocator.cpp index e65e2ab15..91ea692ee 100644 --- a/src/torrent_peer_allocator.cpp +++ b/src/torrent_peer_allocator.cpp @@ -59,7 +59,7 @@ namespace libtorrent switch(type) { case torrent_peer_allocator_interface::ipv4_peer_type: - p = (torrent_peer*)m_ipv4_peer_pool.malloc(); + p = static_cast(m_ipv4_peer_pool.malloc()); if (p == NULL) return NULL; m_ipv4_peer_pool.set_next_size(500); m_total_bytes += sizeof(libtorrent::ipv4_peer); @@ -69,7 +69,7 @@ namespace libtorrent break; #if TORRENT_USE_IPV6 case torrent_peer_allocator_interface::ipv6_peer_type: - p = (torrent_peer*)m_ipv6_peer_pool.malloc(); + p = static_cast(m_ipv6_peer_pool.malloc()); if (p == NULL) return NULL; m_ipv6_peer_pool.set_next_size(500); m_total_bytes += sizeof(libtorrent::ipv6_peer); @@ -80,7 +80,7 @@ namespace libtorrent #endif #if TORRENT_USE_I2P case torrent_peer_allocator_interface::i2p_peer_type: - p = (torrent_peer*)m_i2p_peer_pool.malloc(); + p = static_cast(m_i2p_peer_pool.malloc()); if (p == NULL) return NULL; m_i2p_peer_pool.set_next_size(500); m_total_bytes += sizeof(libtorrent::i2p_peer); @@ -98,7 +98,7 @@ namespace libtorrent #if TORRENT_USE_IPV6 if (p->is_v6_addr) { - TORRENT_ASSERT(m_ipv6_peer_pool.is_from((libtorrent::ipv6_peer*)p)); + TORRENT_ASSERT(m_ipv6_peer_pool.is_from(static_cast(p))); static_cast(p)->~ipv6_peer(); m_ipv6_peer_pool.free(p); TORRENT_ASSERT(m_live_bytes >= sizeof(ipv6_peer)); @@ -111,7 +111,7 @@ namespace libtorrent #if TORRENT_USE_I2P if (p->is_i2p_addr) { - TORRENT_ASSERT(m_i2p_peer_pool.is_from((libtorrent::i2p_peer*)p)); + TORRENT_ASSERT(m_i2p_peer_pool.is_from(static_cast(p))); static_cast(p)->~i2p_peer(); m_i2p_peer_pool.free(p); TORRENT_ASSERT(m_live_bytes >= sizeof(i2p_peer)); @@ -121,7 +121,7 @@ namespace libtorrent return; } #endif - TORRENT_ASSERT(m_ipv4_peer_pool.is_from((libtorrent::ipv4_peer*)p)); + TORRENT_ASSERT(m_ipv4_peer_pool.is_from(static_cast(p))); static_cast(p)->~ipv4_peer(); m_ipv4_peer_pool.free(p); TORRENT_ASSERT(m_live_bytes >= sizeof(ipv4_peer)); diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index ff97b2d89..e5574a823 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -94,7 +94,7 @@ udp_socket::udp_socket(io_service& ios) m_buf_size = 2048; m_new_buf_size = m_buf_size; - m_buf = (char*)malloc(m_buf_size); + m_buf = static_cast(malloc(m_buf_size)); } udp_socket::~udp_socket() @@ -281,14 +281,14 @@ void udp_socket::on_read(error_code const& ec, udp::socket* s) for (;;) { - error_code ec; + error_code err; udp::endpoint ep; - size_t bytes_transferred = s->receive_from(boost::asio::buffer(m_buf, m_buf_size), ep, 0, ec); + size_t bytes_transferred = s->receive_from(boost::asio::buffer(m_buf, m_buf_size), ep, 0, err); // TODO: it would be nice to detect this on posix systems also #ifdef TORRENT_WINDOWS - if ((ec == error_code(ERROR_MORE_DATA, system_category()) - || ec == error_code(WSAEMSGSIZE, system_category())) + if ((err == error_code(ERROR_MORE_DATA, system_category()) + || err == error_code(WSAEMSGSIZE, system_category())) && m_buf_size < 65536) { // if this function fails to allocate memory, m_buf_size @@ -299,8 +299,8 @@ void udp_socket::on_read(error_code const& ec, udp::socket* s) } #endif - if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) break; - on_read_impl(ep, ec, bytes_transferred); + if (err == boost::asio::error::would_block || err == boost::asio::error::try_again) break; + on_read_impl(ep, err, bytes_transferred); } call_drained_handler(); setup_read(s); @@ -1279,7 +1279,7 @@ void udp_socket::connect2(error_code const& e) else { // in this case we need to read more data from the socket - TORRENT_ASSERT(false && "not implemented yet!"); + TORRENT_ASSERT(false); drain_queue(); return; } diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 13e5ea39d..b921d04f8 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -527,7 +527,7 @@ namespace libtorrent if (cb) { char hex_ih[41]; - to_hex((char const*)&tracker_req().info_hash[0], 20, hex_ih); + to_hex(tracker_req().info_hash.data(), 20, hex_ih); cb->debug_log("==> UDP_TRACKER_CONNECT [ to: %s ih: %s]" , m_hostname.empty() ? print_endpoint(m_target).c_str() @@ -757,7 +757,7 @@ namespace libtorrent if (cb) { char hex_ih[41]; - to_hex((char const*)&req.info_hash[0], 20, hex_ih); + to_hex(req.info_hash.data(), 20, hex_ih); cb->debug_log("==> UDP_TRACKER_ANNOUNCE [%s]", hex_ih); } #endif