fix warnings

This commit is contained in:
arvidn 2015-08-08 22:53:11 -04:00
parent 27c5a28637
commit 1c1698459c
12 changed files with 73 additions and 71 deletions

View File

@ -219,11 +219,11 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_USE_ICONV 0
#define TORRENT_USE_IFADDRS 0
#define TORRENT_USE_MEMALIGN 1
#define TORRENT_HAVE_FDATASYNC 0
#define TORRENT_USE_FDATASYNC 0
#else // ANDROID
#define TORRENT_USE_IFADDRS 1
#define TORRENT_USE_POSIX_MEMALIGN 1
#define TORRENT_HAVE_FDATASYNC 1
#define TORRENT_USE_FDATASYNC 1
#endif // ANDROID
#if defined __GLIBC__ && ( defined __x86_64__ || defined __i386 \

View File

@ -1082,7 +1082,7 @@ namespace libtorrent
buffer::const_interval recv_buffer = m_recv_buffer.get();
bitfield bits;
bits.assign((char*)recv_buffer.begin + 1
bits.assign(recv_buffer.begin + 1
, t->valid_metadata()?get_bitfield().size():(m_recv_buffer.packet_size()-1)*8);
incoming_bitfield(bits);
@ -1131,7 +1131,7 @@ namespace libtorrent
boost::shared_ptr<torrent> t = associated_torrent().lock();
TORRENT_ASSERT(t);
bool merkle = (unsigned char)recv_buffer.begin[0] == 250;
bool merkle = static_cast<boost::uint8_t>(recv_buffer.begin[0]) == 250;
if (merkle)
{
if (recv_pos == 1)
@ -1927,7 +1927,7 @@ namespace libtorrent
buffer::const_interval recv_buffer = m_recv_buffer.get();
TORRENT_ASSERT(recv_buffer.left() >= 1);
int packet_type = (unsigned char)recv_buffer[0];
int packet_type = static_cast<boost::uint8_t>(recv_buffer[0]);
if (m_settings.get_bool(settings_pack::support_merkle_torrents)
&& packet_type == 250) packet_type = msg_piece;
@ -1948,9 +1948,6 @@ namespace libtorrent
#endif
received_bytes(0, received);
// What's going on here?!
// break in debug builds to allow investigation
// TORRENT_ASSERT(false);
disconnect(errors::invalid_message, op_bittorrent);
return m_recv_buffer.packet_finished();
}
@ -2178,10 +2175,10 @@ namespace libtorrent
}
const int packet_size = (num_pieces + 7) / 8 + 5;
char* msg = TORRENT_ALLOCA(char, packet_size);
boost::uint8_t* msg = TORRENT_ALLOCA(boost::uint8_t, packet_size);
if (msg == 0) return; // out of memory
unsigned char* ptr = (unsigned char*)msg;
unsigned char* ptr = msg;
detail::write_int32(packet_size - 4, ptr);
detail::write_uint8(msg_bitfield, ptr);
@ -2191,7 +2188,7 @@ namespace libtorrent
memset(ptr, 0xff, packet_size - 5);
// Clear trailing bits
unsigned char *p = ((unsigned char *)msg) + packet_size - 1;
unsigned char *p = msg + packet_size - 1;
*p = (0xff << ((8 - (num_pieces & 7)) & 7)) & 0xff;
}
else
@ -2233,7 +2230,7 @@ namespace libtorrent
#endif
m_sent_bitfield = true;
send_buffer(msg, packet_size);
send_buffer(reinterpret_cast<char const*>(msg), packet_size);
stats_counters().inc_stats_counter(counters::num_outgoing_bitfield);
@ -2350,9 +2347,9 @@ namespace libtorrent
char msg[6];
char* ptr = msg;
// write the length of the message
detail::write_int32((int)dict_msg.size() + 2, ptr);
detail::write_int32(int(dict_msg.size()) + 2, ptr);
detail::write_uint8(msg_extended, ptr);
// signal handshake message
detail::write_uint8(0, ptr);
@ -2471,14 +2468,14 @@ namespace libtorrent
void buffer_reclaim_block(char* /* buffer */, void* userdata
, block_cache_reference ref)
{
buffer_allocator_interface* buf = (buffer_allocator_interface*)userdata;
buffer_allocator_interface* buf = static_cast<buffer_allocator_interface*>(userdata);
buf->reclaim_block(ref);
}
void buffer_free_disk_buf(char* buffer, void* userdata
, block_cache_reference /* ref */)
{
buffer_allocator_interface* buf = (buffer_allocator_interface*)userdata;
buffer_allocator_interface* buf = static_cast<buffer_allocator_interface*>(userdata);
buf->free_disk_buffer(buffer);
}
@ -2516,7 +2513,7 @@ namespace libtorrent
// is 0, we need to include the merkle node hashes
if (merkle)
{
std::vector<char> piece_list_buf;
std::vector<char> piece_list_buf;
entry piece_list;
entry::list_type& l = piece_list.list();
std::map<int, sha1_hash> merkle_node_list = t->torrent_file().build_merkle_list(r.piece);
@ -2530,8 +2527,10 @@ namespace libtorrent
bencode(std::back_inserter(piece_list_buf), piece_list);
detail::write_int32(piece_list_buf.size(), ptr);
char* ptr = msg;
detail::write_int32(r.length + 1 + 4 + 4 + 4 + piece_list_buf.size(), ptr);
// back-patch the length field
char* ptr2 = msg;
detail::write_int32(r.length + 1 + 4 + 4 + 4 + piece_list_buf.size()
, ptr2);
send_buffer(msg, 17);
send_buffer(&piece_list_buf[0], piece_list_buf.size());
@ -2728,10 +2727,10 @@ namespace libtorrent
}
}
int syncoffset = get_syncoffset((char*)m_sync_hash->begin(), 20
int syncoffset = get_syncoffset(m_sync_hash->data(), 20
, recv_buffer.begin, recv_buffer.left());
// No sync
// No sync
if (syncoffset == -1)
{
received_bytes(0, bytes_transferred);
@ -3301,7 +3300,7 @@ namespace libtorrent
// info_hash we got from the peer
sha1_hash info_hash;
std::copy(recv_buffer.begin + 8, recv_buffer.begin + 28
, (char*)info_hash.begin());
, info_hash.data());
attach_to_torrent(info_hash);
if (is_disconnecting()) return;
@ -3310,7 +3309,7 @@ namespace libtorrent
{
// verify info hash
if (!std::equal(recv_buffer.begin + 8, recv_buffer.begin + 28
, (const char*)t->torrent_file().info_hash().begin()))
, t->torrent_file().info_hash().data()))
{
#ifndef TORRENT_DISABLE_LOGGING
peer_log(peer_log_alert::info, "ERROR", "received invalid info_hash");
@ -3326,7 +3325,7 @@ namespace libtorrent
t = associated_torrent().lock();
TORRENT_ASSERT(t);
// if this is a local connection, we have already
// sent the handshake
if (!is_outgoing()) write_handshake();
@ -3612,9 +3611,9 @@ namespace libtorrent
m_payloads.erase(m_payloads.begin(), first_to_keep);
}
TORRENT_ASSERT(amount_payload <= (int)bytes_transferred);
TORRENT_ASSERT(amount_payload <= int(bytes_transferred));
sent_bytes(amount_payload, bytes_transferred - amount_payload);
if (amount_payload > 0)
{
boost::shared_ptr<torrent> t = associated_torrent().lock();

View File

@ -1837,7 +1837,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
free(tmp.iov_base);
#endif
#if TORRENT_HAVE_FDATASYNC \
#if TORRENT_USE_FDATASYNC \
&& !defined F_NOCACHE && \
!defined DIRECTIO_ON
if (m_open_mode & no_cache)
@ -2075,7 +2075,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
return false;
}
// ok, let's try to allocate non contiguous space then
fstore_t f = {F_ALLOCATEALL, F_PEOFPOSMODE, 0, s, 0};
f.fst_flags = F_ALLOCATEALL;
if (fcntl(native_handle(), F_PREALLOCATE, &f) < 0)
{
ec.assign(errno, generic_category());

View File

@ -148,9 +148,9 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri
#endif
)
{
error_code ec(errors::unsupported_url_protocol);
error_code err(errors::unsupported_url_protocol);
m_timer.get_io_service().post(boost::bind(&http_connection::callback
, me, ec, static_cast<char*>(NULL), 0));
, me, err, static_cast<char*>(NULL), 0));
return;
}
@ -275,8 +275,8 @@ void http_connection::start(std::string const& hostname, int port
{
m_ssl = ssl;
m_bind_addr = bind_addr;
error_code ec;
if (m_sock.is_open()) m_sock.close(ec);
error_code err;
if (m_sock.is_open()) m_sock.close(err);
#if TORRENT_USE_I2P
bool is_i2p = false;
@ -348,7 +348,6 @@ void http_connection::start(std::string const& hostname, int port
if (m_bind_addr != address_v4::any())
{
error_code ec;
m_sock.open(m_bind_addr.is_v4()?tcp::v4():tcp::v6(), ec);
m_sock.bind(tcp::endpoint(m_bind_addr, 0), ec);
if (ec)
@ -631,7 +630,7 @@ void http_connection::callback(error_code e, char* data, int size)
std::vector<char> buf;
if (data && m_bottled && m_parser.header_finished())
{
size = m_parser.collapse_chunk_headers((char*)data, size);
size = m_parser.collapse_chunk_headers(data, size);
std::string const& encoding = m_parser.header("content-encoding");
if ((encoding == "gzip" || encoding == "x-gzip") && size > 0 && data)

View File

@ -513,7 +513,7 @@ restart_response:
return buffer::const_interval(m_recv_buffer.begin + m_body_start_pos
, m_recv_buffer.begin + last_byte);
}
void http_parser::reset()
{
m_method.clear();
@ -534,7 +534,7 @@ restart_response:
m_chunk_header_size = 0;
m_partial_chunk_header = 0;
}
int http_parser::collapse_chunk_headers(char* buffer, int size) const
{
if (!chunked_encoding()) return size;
@ -542,7 +542,7 @@ restart_response:
// go through all chunks and compact them
// since we're bottled, and the buffer is our after all
// it's OK to mutate it
char* write_ptr = (char*)buffer;
char* write_ptr = buffer;
// the offsets in the array are from the start of the
// buffer, not start of the body, so subtract the size
// of the HTTP header from them

View File

@ -300,10 +300,10 @@ namespace
, tmp, &compare_id);
#ifndef NDEBUG
for (int i = 1; i < size; ++i)
for (int j = 1; j < size; ++j)
{
TORRENT_ASSERT(compare_id(name_map[i-1]
, name_map[i]));
TORRENT_ASSERT(compare_id(name_map[j-1]
, name_map[j]));
}
#endif
@ -334,7 +334,7 @@ namespace
return identity;
}
bool find_string(unsigned char const* id, char const* search)
bool find_string(char const* id, char const* search)
{
return std::equal(search, search + std::strlen(search), id);
}
@ -362,7 +362,7 @@ namespace libtorrent
std::string identify_client(peer_id const& p)
{
peer_id::const_iterator PID = p.begin();
char const* PID = p.data();
boost::optional<fingerprint> f;
if (p.is_all_zeros()) return "Unknown";
@ -380,11 +380,11 @@ namespace libtorrent
}
if (find_string(PID, "-BOW") && PID[7] == '-')
return "Bits on Wheels " + std::string((char const*)PID + 4, (char const*)PID + 7);
return "Bits on Wheels " + std::string(PID + 4, (char const*)PID + 7);
if (find_string(PID, "eX"))
{
std::string user((char const*)PID + 2, (char const*)PID + 14);
std::string user(PID + 2, PID + 14);
return std::string("eXeem ('") + user.c_str() + "')";
}

View File

@ -157,7 +157,7 @@ namespace libtorrent {
while (new_size < size)
new_size <<= 1;
void** new_storage = (void**)malloc(sizeof(void*) * new_size);
void** new_storage = static_cast<void**>(malloc(sizeof(void*) * new_size));
#ifndef BOOST_NO_EXCEPTIONS
if (new_storage == NULL) throw std::bad_alloc();
#endif

View File

@ -5797,7 +5797,7 @@ namespace libtorrent
, block_cache_reference ref)
{
TORRENT_ASSERT(is_single_thread());
m_send_buffer.append_buffer((char*)buffer, size, size, destructor
m_send_buffer.append_buffer(const_cast<char*>(buffer), size, size, destructor
, userdata, ref);
}
@ -6522,7 +6522,7 @@ namespace libtorrent
}
else if (!m_in_constructor)
{
TORRENT_ASSERT(m_ses.has_peer((peer_connection*)this));
TORRENT_ASSERT(m_ses.has_peer(this));
}
TORRENT_ASSERT(m_outstanding_bytes >= 0);

View File

@ -569,7 +569,6 @@ namespace libtorrent
INVARIANT_CHECK;
error_code ec;
TORRENT_ASSERT(!state->is_paused);
iterator iter;
@ -721,7 +720,6 @@ namespace libtorrent
{
// we don't have any info about this peer.
// add a new entry
error_code ec;
if (state->max_peerlist_size
&& int(m_peers.size()) >= state->max_peerlist_size)

View File

@ -366,7 +366,7 @@ namespace aux {
, m_alert_pointer_pos(0)
#endif
, m_disk_thread(m_io_service, m_stats_counters
, (uncork_interface*)this)
, static_cast<uncork_interface*>(this))
, m_download_rate(peer_connection::download_channel)
, m_upload_rate(peer_connection::upload_channel)
, m_global_class(0)
@ -1346,8 +1346,8 @@ namespace aux {
if (t->next != NULL || t->prev != NULL || m_torrent_lru.front() == t)
{
#ifdef TORRENT_DEBUG
torrent* i = (torrent*)m_torrent_lru.front();
while (i != NULL && i != t) i = (torrent*)i->next;
torrent* i = static_cast<torrent*>(m_torrent_lru.front());
while (i != NULL && i != t) i = static_cast<torrent*>(i->next);
TORRENT_ASSERT(i == t);
#endif
@ -1386,8 +1386,8 @@ namespace aux {
TORRENT_ASSERT(t->next != NULL || t->prev != NULL || m_torrent_lru.front() == t);
#if defined TORRENT_DEBUG && defined TORRENT_EXPENSIVE_INVARIANT_CHECKS
torrent* i = (torrent*)m_torrent_lru.front();
while (i != NULL && i != t) i = (torrent*)i->next;
torrent* i = static_cast<torrent*>(m_torrent_lru.front());
while (i != NULL && i != t) i = static_cast<torrent*>(i->next);
TORRENT_ASSERT(i == t);
#endif
@ -1425,8 +1425,8 @@ namespace aux {
if (ignore->next != NULL || ignore->prev != NULL || m_torrent_lru.front() == ignore)
{
#ifdef TORRENT_DEBUG
torrent* i = (torrent*)m_torrent_lru.front();
while (i != NULL && i != ignore) i = (torrent*)i->next;
torrent* i = static_cast<torrent*>(m_torrent_lru.front());
while (i != NULL && i != ignore) i = static_cast<torrent*>(i->next);
TORRENT_ASSERT(i == ignore);
#endif
++loaded_limit;
@ -1436,11 +1436,11 @@ namespace aux {
{
// we're at the limit of loaded torrents. Find the least important
// torrent and unload it. This is done with an LRU.
torrent* i = (torrent*)m_torrent_lru.front();
torrent* i = static_cast<torrent*>(m_torrent_lru.front());
if (i == ignore)
{
i = (torrent*)i->next;
i = static_cast<torrent*>(i->next);
if (i == NULL) break;
}
m_stats_counters.inc_stats_counter(counters::torrent_evicted_counter);
@ -4416,7 +4416,7 @@ retry:
void session_impl::on_async_load_torrent(disk_io_job const* j)
{
add_torrent_params* params = (add_torrent_params*)j->requester;
add_torrent_params* params = static_cast<add_torrent_params*>(j->requester);
error_code ec;
torrent_handle handle;
if (j->error.ec)
@ -4908,7 +4908,7 @@ retry:
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
hasher h;
h.update("req2", 4);
h.update((char*)&tptr->info_hash()[0], 20);
h.update(tptr->info_hash().data(), 20);
m_obfuscated_torrents.erase(h.final());
#endif
@ -5094,7 +5094,7 @@ retry:
std::copy(print.begin(), print.begin() + print.length(), m_peer_id.begin());
if (print.length() < 20)
{
url_random((char*)&m_peer_id[print.length()], (char*)&m_peer_id[0] + 20);
url_random(m_peer_id.data() + print.length(), m_peer_id.data() + 20);
}
}
@ -5393,7 +5393,7 @@ retry:
INVARIANT_CHECK;
stop_dht();
m_dht = boost::make_shared<dht::dht_tracker>((dht_observer*)this
m_dht = boost::make_shared<dht::dht_tracker>(static_cast<dht_observer*>(this)
, boost::ref(m_udp_socket), boost::cref(m_dht_settings)
, boost::ref(m_stats_counters), &startup_state);
@ -6024,7 +6024,7 @@ retry:
if (!m_settings.get_bool(settings_pack::anonymous_mode)) return;
m_settings.set_str(settings_pack::user_agent, "");
url_random((char*)&m_peer_id[0], (char*)&m_peer_id[0] + 20);
url_random(m_peer_id.data(), m_peer_id.data() + 20);
}
void session_impl::update_force_proxy()
@ -6385,9 +6385,9 @@ retry:
, int local_port)
{
int ret = 0;
if (m_upnp) ret = m_upnp->add_mapping((upnp::protocol_type)t, external_port
if (m_upnp) ret = m_upnp->add_mapping(static_cast<upnp::protocol_type>(t), external_port
, local_port);
if (m_natpmp) ret = m_natpmp->add_mapping((natpmp::protocol_type)t, external_port
if (m_natpmp) ret = m_natpmp->add_mapping(static_cast<natpmp::protocol_type>(t), external_port
, local_port);
return ret;
}
@ -6576,9 +6576,9 @@ retry:
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
int num_bytes = send_buffer_size();
return (char*)malloc(num_bytes);
return static_cast<char*>(malloc(num_bytes));
#else
return (char*)m_send_buffers.malloc();
return static_cast<char*>(m_send_buffers.malloc());
#endif
}
@ -6626,7 +6626,7 @@ retry:
#endif
for (list_iterator i = m_torrent_lru.iterate(); i.get(); i.next())
{
torrent* t = (torrent*)i.get();
torrent* t = static_cast<torrent*>(i.get());
TORRENT_ASSERT(t->is_loaded());
TORRENT_ASSERT(unique_torrents.count(t) == 0);
unique_torrents.insert(t);

View File

@ -458,6 +458,9 @@ namespace libtorrent
}
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/aux_/disable_warnings_push.hpp"
boost::shared_ptr<settings_pack> load_pack_from_struct(
aux::session_settings const& current, session_settings const& s)
{
@ -539,6 +542,9 @@ namespace libtorrent
ret.peer_turnover = float(current.get_int(settings_pack::peer_turnover)) / 100.f;
ret.peer_turnover_cutoff = float(current.get_int(settings_pack::peer_turnover_cutoff)) / 100.f;
}
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#endif
void initialize_default_settings(aux::session_settings& s)

View File

@ -86,7 +86,7 @@ void log_hash_block(FILE** f, libtorrent::torrent const& t, int piece, int block
file_storage const& fs = t.torrent_file().files();
std::vector<file_slice> files = fs.map_block(piece, block * 0x4000, len);
std::string fn = fs.file_path(fs.internal_at(files[0].file_index));
char filename[4094];
@ -94,7 +94,7 @@ void log_hash_block(FILE** f, libtorrent::torrent const& t, int piece, int block
for (int i = 0; i < files.size(); ++i)
{
offset += snprintf(filename+offset, sizeof(filename)-offset
, "%s[%"PRId64",%d]", libtorrent::filename(fn).c_str(), files[i].offset, int(files[i].size));
, "%s[%" PRId64 ",%d]", libtorrent::filename(fn).c_str(), files[i].offset, int(files[i].size));
if (offset >= sizeof(filename)) break;
}