merged compiler warning fixes from RC_1_0

This commit is contained in:
Arvid Norberg 2014-07-05 14:10:25 +00:00
parent 6c6fe4dfe2
commit 6ef1b98717
16 changed files with 74 additions and 53 deletions

View File

@ -1,3 +1,5 @@
* fix compiler warnings
1.0 release
* fix bugs in convert_to/from_native() on windows

View File

@ -24,11 +24,13 @@ namespace {
allow_threading_guard guard;
p.url = uri;
#ifndef BOOST_NO_EXCEPTIONS
return add_magnet_uri(s, uri, p);
return s.add_torrent(p);
#else
error_code ec;
return add_magnet_uri(s, uri, p, ec);
return s.add_torrent(p, ec);
#endif
}
#endif

View File

@ -47,13 +47,13 @@ struct unicode_from_python
#endif
if (len > -1)
{
assert(len < str.size());
assert(len < int(str.size()));
str[len] = 0;
}
else str[str.size()-1] = 0;
std::string utf8;
int ret = wchar_utf8(str, utf8);
wchar_utf8(str, utf8);
new (storage) std::string(utf8);
}
else

View File

@ -79,7 +79,8 @@ static boost::detail::atomic_count num_seeds(0);
// a client and dual uploads and downloads from a client
// at the same time (this is presumably the most realistic
// test)
enum { none, upload_test, download_test, dual_test } test_mode = none;
enum test_mode_t{ none, upload_test, download_test, dual_test };
test_mode_t test_mode = none;
// the number of suggest messages received (total across all peers)
boost::detail::atomic_count num_suggest(0);
@ -449,7 +450,7 @@ struct peer_conn
{
pieces.reserve(num_pieces);
int piece = 0;
for (int i = 0; i < bytes_transferred; ++i)
for (int i = 0; i < int(bytes_transferred); ++i)
{
int mask = 0x80;
for (int k = 0; k < 8; ++k)
@ -476,7 +477,7 @@ struct peer_conn
--outstanding_requests;
int piece = detail::read_int32(ptr);
int start = detail::read_int32(ptr);
if ((start + bytes_transferred) / 0x4000 == blocks_per_piece)
if (int((start + bytes_transferred) / 0x4000) == blocks_per_piece)
{
write_have(piece);
return;

View File

@ -323,7 +323,7 @@ int main(int argc, char* argv[])
return 1;
}
int ret = fwrite(&t.merkle_tree()[0], 20, t.merkle_tree().size(), output);
if (ret != t.merkle_tree().size())
if (ret != int(t.merkle_tree().size()))
{
fprintf(stderr, "failed to write %s: (%d) %s\n"
, merklefile.c_str(), errno, strerror(errno));

View File

@ -309,6 +309,8 @@ namespace libtorrent
void rename_file(int index, std::wstring const& new_filename) TORRENT_DEPRECATED;
TORRENT_DEPRECATED_PREFIX
void set_name(std::wstring const& n) TORRENT_DEPRECATED;
void rename_file_deprecated(int index, std::wstring const& new_filename);
#endif // TORRENT_NO_DEPRECATE
#endif // TORRENT_USE_WSTRING

View File

@ -1612,7 +1612,7 @@ namespace libtorrent
int unchoke_limit = m_settings.unchoke_slots_limit;
if (unchoke_limit < 0) unchoke_limit = 100;
if (m_sorted_read_jobs.size() > unchoke_limit * 2)
if (int(m_sorted_read_jobs.size()) > unchoke_limit * 2)
{
int range = unchoke_limit;
int exceed = m_sorted_read_jobs.size() - range * 2;

View File

@ -209,7 +209,7 @@ namespace libtorrent
m_name = utf8;
}
void file_storage::rename_file(int index, std::wstring const& new_filename)
void file_storage::rename_file_deprecated(int index, std::wstring const& new_filename)
{
TORRENT_ASSERT_PRECOND(index >= 0 && index < int(m_files.size()));
std::string utf8;
@ -225,6 +225,11 @@ namespace libtorrent
wchar_utf8(file, utf8);
add_file(utf8, size, flags, mtime, symlink_path);
}
void file_storage::rename_file(int index, std::wstring const& new_filename)
{
rename_file_deprecated(index, new_filename);
}
#endif // TORRENT_NO_DEPRECATE
#endif // TORRENT_USE_WSTRING

View File

@ -73,7 +73,7 @@ int routing_table::bucket_limit(int bucket) const
if (!m_settings.extended_routing_table) return m_bucket_size;
const static int size_exceptions[] = {16, 8, 4, 2};
if (bucket < sizeof(size_exceptions)/sizeof(size_exceptions[0]))
if (bucket < int(sizeof(size_exceptions)/sizeof(size_exceptions[0])))
return m_bucket_size * size_exceptions[bucket];
return m_bucket_size;
}
@ -678,7 +678,7 @@ bool routing_table::add_node(node_entry e)
// find node entries with duplicate prefixes in O(1)
std::vector<bucket_t::iterator> prefix(1 << (8 - mask_shift), b.end());
TORRENT_ASSERT(prefix.size() >= bucket_size_limit);
TORRENT_ASSERT(int(prefix.size()) >= bucket_size_limit);
// the begin iterator from this object is used as a placeholder
// for an occupied slot whose node has already been added to the
@ -692,7 +692,7 @@ bool routing_table::add_node(node_entry e)
id <<= bucket_index + 1;
int this_prefix = (id[0] & mask) >> mask_shift;
TORRENT_ASSERT(this_prefix >= 0);
TORRENT_ASSERT(this_prefix < prefix.size());
TORRENT_ASSERT(this_prefix < int(prefix.size()));
if (prefix[this_prefix] != b.end())
{
// there's already a node with this prefix. Remember both
@ -810,7 +810,7 @@ void routing_table::split_bucket()
int bucket_index = m_buckets.size()-1;
int bucket_size_limit = bucket_limit(bucket_index);
TORRENT_ASSERT(m_buckets.back().live_nodes.size() >= bucket_size_limit);
TORRENT_ASSERT(int(m_buckets.back().live_nodes.size()) >= bucket_size_limit);
// this is the last bucket, and it's full already. Split
// it by adding another bucket

View File

@ -111,6 +111,21 @@ namespace libtorrent
}
#ifndef TORRENT_NO_DEPRECATE
torrent_handle add_magnet_uri_deprecated(session& ses, std::string const& uri
, add_torrent_params p, error_code& ec)
{
parse_magnet_uri(uri, p, ec);
if (ec) return torrent_handle();
return ses.add_torrent(p, ec);
}
torrent_handle add_magnet_uri(session& ses, std::string const& uri
, add_torrent_params p, error_code& ec)
{
return add_magnet_uri_deprecated(ses, uri, p, ec);
}
#ifndef BOOST_NO_EXCEPTIONS
torrent_handle add_magnet_uri(session& ses, std::string const& uri
, std::string const& save_path
@ -119,47 +134,40 @@ namespace libtorrent
, storage_constructor_type sc
, void* userdata)
{
std::string name;
std::string tracker;
add_torrent_params params(sc);
params.storage_mode = storage_mode;
params.userdata = userdata;
params.save_path = save_path;
if (paused) params.flags |= add_torrent_params::flag_paused;
else params.flags &= ~add_torrent_params::flag_paused;
error_code ec;
std::string display_name = url_has_argument(uri, "dn");
if (!display_name.empty()) name = unescape_string(display_name.c_str(), ec);
if (!display_name.empty()) params.name = unescape_string(display_name.c_str(), ec);
std::string tracker_string = url_has_argument(uri, "tr");
if (!tracker_string.empty()) tracker = unescape_string(tracker_string.c_str(), ec);
if (!tracker_string.empty()) params.trackers.push_back(unescape_string(tracker_string.c_str(), ec));
std::string btih = url_has_argument(uri, "xt");
if (btih.empty()) return torrent_handle();
if (btih.compare(0, 9, "urn:btih:") != 0) return torrent_handle();
sha1_hash info_hash;
if (btih.size() == 40 + 9) from_hex(&btih[9], 40, (char*)&info_hash[0]);
else info_hash.assign(base32decode(btih.substr(9)));
if (btih.size() == 40 + 9) from_hex(&btih[9], 40, (char*)&params.info_hash[0]);
else params.info_hash.assign(base32decode(btih.substr(9)));
return ses.add_torrent(tracker.empty() ? 0 : tracker.c_str(), info_hash
, name.empty() ? 0 : name.c_str(), save_path, entry()
, storage_mode, paused, sc, userdata);
return ses.add_torrent(params);
}
torrent_handle add_magnet_uri(session& ses, std::string const& uri
, add_torrent_params p)
{
error_code ec;
torrent_handle ret = add_magnet_uri(ses, uri, p, ec);
torrent_handle ret = add_magnet_uri_deprecated(ses, uri, p, ec);
if (ec) throw libtorrent_exception(ec);
return ret;
}
#endif // BOOST_NO_EXCEPTIONS
torrent_handle add_magnet_uri(session& ses, std::string const& uri
, add_torrent_params p, error_code& ec)
{
parse_magnet_uri(uri, p, ec);
if (ec) return torrent_handle();
return ses.add_torrent(p, ec);
}
#endif // TORRENT_NO_DEPRECATE
void parse_magnet_uri(std::string const& uri, add_torrent_params& p, error_code& ec)

View File

@ -2681,8 +2681,8 @@ retry:
// to test SSL connections, one can use this openssl command template:
//
// openssl s_client -cert <client-cert>.pem -key <client-private-key>.pem \
// -CAfile <torrent-cert>.pem -debug -connect 127.0.0.1:4433 -tls1 \
// openssl s_client -cert <client-cert>.pem -key <client-private-key>.pem
// -CAfile <torrent-cert>.pem -debug -connect 127.0.0.1:4433 -tls1
// -servername <hex-encoded-info-hash>
void session_impl::ssl_handshake(error_code const& ec, boost::shared_ptr<socket_type> s)
@ -3106,7 +3106,7 @@ retry:
#ifndef TORRENT_DISABLE_DHT
if (m_dht_interval_update_torrents < 40
&& m_dht_interval_update_torrents != m_torrents.size())
&& m_dht_interval_update_torrents != int(m_torrents.size()))
update_dht_announce_interval();
#endif

View File

@ -579,7 +579,7 @@ namespace libtorrent
m_ses.m_torrents.insert(std::make_pair(m_torrent_file->info_hash(), me));
if (!m_uuid.empty()) m_ses.m_uuids.insert(std::make_pair(m_uuid, me));
TORRENT_ASSERT(num_torrents == m_ses.m_torrents.size());
TORRENT_ASSERT(num_torrents == int(m_ses.m_torrents.size()));
// if the user added any trackers while downloading the
// .torrent file, serge them into the new tracker list
@ -4059,7 +4059,7 @@ namespace libtorrent
if (valid_metadata() && limit > m_torrent_file->num_files())
limit = m_torrent_file->num_files();
if (m_file_priority.size() < limit)
if (int(m_file_priority.size()) < limit)
m_file_priority.resize(limit);
std::copy(files.begin(), files.begin() + limit, m_file_priority.begin());
@ -4087,7 +4087,7 @@ namespace libtorrent
if (index < 0 || index >= m_torrent_file->num_files()) return;
if (prio < 0) prio = 0;
else if (prio > 7) prio = 7;
if (m_file_priority.size() <= index)
if (int(m_file_priority.size()) <= index)
{
if (prio == 1) return;
m_file_priority.resize(m_torrent_file->num_files(), 1);
@ -4109,7 +4109,7 @@ namespace libtorrent
if (!valid_metadata()) return 1;
if (index < 0 || index >= m_torrent_file->num_files()) return 0;
if (m_file_priority.size() <= index) return 1;
if (int(m_file_priority.size()) <= index) return 1;
return m_file_priority[index];
}
@ -4124,7 +4124,7 @@ namespace libtorrent
}
files->resize(m_torrent_file->num_files(), 1);
TORRENT_ASSERT(m_file_priority.size() <= m_torrent_file->num_files());
TORRENT_ASSERT(int(m_file_priority.size()) <= m_torrent_file->num_files());
std::copy(m_file_priority.begin(), m_file_priority.end(), files->begin());
}
@ -6806,7 +6806,7 @@ namespace libtorrent
int num_uploads = 0;
std::map<piece_block, int> num_requests;
for (const_peer_iterator i = begin(); i != end(); ++i)
for (const_peer_iterator i = this->begin(); i != this->end(); ++i)
{
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
// make sure this peer is not a dangling pointer

View File

@ -778,7 +778,7 @@ namespace libtorrent
void torrent_info::rename_file(int index, std::wstring const& new_filename)
{
copy_on_write();
m_files.rename_file(index, new_filename);
m_files.rename_file_deprecated(index, new_filename);
}
#endif // TORRENT_NO_DEPRECATE
#endif // TORRENT_USE_WSTRING
@ -1451,8 +1451,9 @@ namespace libtorrent
os << "number of pieces: " << num_pieces() << "\n";
os << "piece length: " << piece_length() << "\n";
os << "files:\n";
for (file_storage::iterator i = m_files.begin(); i != m_files.end(); ++i)
os << " " << std::setw(11) << i->size << " " << m_files.file_path(*i) << "\n";
for (int i = 0; i < m_files.num_files(); ++i)
os << " " << std::setw(11) << m_files.file_size(i)
<< " " << m_files.file_path(i) << "\n";
}
// ------- end deprecation -------

View File

@ -685,7 +685,7 @@ namespace libtorrent
detail::write_string(request_string, out);
}
TORRENT_ASSERT(out - buf <= sizeof(buf));
TORRENT_ASSERT(out - buf <= int(sizeof(buf)));
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
boost::shared_ptr<request_callback> cb = requester();

View File

@ -371,7 +371,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
std::vector<ip_interface> net = enum_net_interfaces(m_io_service, ec);
for (std::vector<ip_interface>::const_iterator i = net.begin()
, end(net.end()); i != end && num_chars < sizeof(msg); ++i)
, end(net.end()); i != end && num_chars < int(sizeof(msg)); ++i)
{
num_chars += snprintf(msg + num_chars, sizeof(msg) - num_chars, "(%s,%s) "
, print_address(i->interface_address).c_str(), print_address(i->netmask).c_str());
@ -405,7 +405,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
"%s: IP is not a router. "
, print_endpoint(from).c_str());
for (std::vector<ip_route>::const_iterator i = routes.begin()
, end(routes.end()); i != end && num_chars < sizeof(msg); ++i)
, end(routes.end()); i != end && num_chars < int(sizeof(msg)); ++i)
{
num_chars += snprintf(msg + num_chars, sizeof(msg) - num_chars, "(%s,%s) "
, print_address(i->gateway).c_str(), print_address(i->netmask).c_str());

View File

@ -170,7 +170,7 @@ struct packet
#endif
// the actual packet buffer
boost::uint8_t buf[];
boost::uint8_t buf[1];
};
// since the uTP socket state may be needed after the
@ -2757,7 +2757,7 @@ bool utp_socket_impl::incoming_packet(boost::uint8_t const* buf, int size
m_sm->inc_stats_counter(utp_socket_manager::invalid_pkts_in);
return true;
}
if (ptr - buf + len > size_t(size))
if (ptr - buf + len > ptrdiff_t(size))
{
UTP_LOG("%8p: ERROR: invalid extension header size:%d packet:%d\n"
, this, len, int(ptr - buf));
@ -2962,7 +2962,7 @@ bool utp_socket_impl::incoming_packet(boost::uint8_t const* buf, int size
// (i.e. ST_STATE) we're not ACKing anything. If we just
// received a FIN packet, we need to ack that as well
bool has_ack = ph->get_type() == ST_DATA || ph->get_type() == ST_FIN || ph->get_type() == ST_SYN;
int prev_out_packets = m_out_packets;
boost::uint32_t prev_out_packets = m_out_packets;
// try to send more data as long as we can
// if send_pkt returns true
@ -3457,7 +3457,7 @@ void utp_socket_impl::check_receive_buffers() const
void utp_socket_impl::check_invariant() const
{
for (int i = m_outbuf.cursor();
i != ((m_outbuf.cursor() + m_outbuf.span()) & ACK_MASK);
i != int((m_outbuf.cursor() + m_outbuf.span()) & ACK_MASK);
i = (i + 1) & ACK_MASK)
{
packet* p = (packet*)m_outbuf.at(i);