fix more warnings

This commit is contained in:
arvidn 2015-08-18 16:42:03 +02:00
parent 12da02ae52
commit 26fecaf037
8 changed files with 106 additions and 72 deletions

View File

@ -40,6 +40,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/alert_types.hpp"
#include "libtorrent/disk_observer.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <algorithm>
#include <boost/bind.hpp>
#include <boost/system/error_code.hpp>
@ -55,6 +57,10 @@ POSSIBILITY OF SUCH DAMAGE.
#if TORRENT_USE_RLIMIT
#include <sys/resource.h>
// capture this here where warnings are disabled (the macro generates warnings)
const rlim_t rlimit_as = RLIMIT_AS;
const rlim_t rlim_infinity = RLIM_INFINITY;
#endif
#ifdef TORRENT_LINUX
@ -67,6 +73,8 @@ POSSIBILITY OF SUCH DAMAGE.
// http://www.opensource.apple.com/source/xnu/xnu-792.13.8/osfmk/vm/vm_object.c
#endif
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent
{
// this is posted to the network thread
@ -479,7 +487,7 @@ namespace libtorrent
if (ret > 0)
{
struct rlimit r;
if (getrlimit(RLIMIT_AS, &r) == 0 && r.rlim_cur != RLIM_INFINITY)
if (getrlimit(rlimit_as, &r) == 0 && r.rlim_cur != rlim_infinity)
{
if (ret > r.rlim_cur)
ret = r.rlim_cur;

View File

@ -31,15 +31,18 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/config.hpp"
#include <boost/bind.hpp>
#include <vector>
#include <stdlib.h> // for wcstombscstombs
#include "libtorrent/enum_net.hpp"
#include "libtorrent/broadcast_socket.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/socket_type.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/asio/ip/host_name.hpp>
#include <boost/bind.hpp>
#include <vector>
#include <stdlib.h> // for wcstombscstombs
#if TORRENT_USE_IFCONF
#include <sys/ioctl.h>
@ -85,6 +88,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include <ifaddrs.h>
#endif
#if TORRENT_USE_IFADDRS
// capture this here where warnings are disabled (the macro generates warnings)
const int siocgifmtu = SIOCGIFMTU;
#endif
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#if defined(TORRENT_OS2) && !defined(IF_NAMESIZE)
#define IF_NAMESIZE IFNAMSIZ
#endif
@ -212,7 +222,7 @@ namespace libtorrent { namespace
ifreq req;
memset(&req, 0, sizeof(req));
if_indextoname(if_index, req.ifr_name);
ioctl(s, SIOCGIFMTU, &req);
ioctl(s, siocgifmtu, &req);
rt_info->mtu = req.ifr_mtu;
// obviously this doesn't work correctly. How do you get the netmask for a route?
// if (ioctl(s, SIOCGIFNETMASK, &req) == 0) {
@ -268,7 +278,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
ifreq req;
memset(&req, 0, sizeof(req));
if_indextoname(rtm->rtm_index, req.ifr_name);
if (ioctl(s, SIOCGIFMTU, &req) < 0) return false;
if (ioctl(s, siocgifmtu, &req) < 0) return false;
rt_info->mtu = req.ifr_mtu;
return true;
@ -448,7 +458,7 @@ namespace libtorrent
memset(&req, 0, sizeof(req));
// -1 to leave a null terminator
strncpy(req.ifr_name, iface.name, IF_NAMESIZE - 1);
if (ioctl(s, SIOCGIFMTU, &req) < 0)
if (ioctl(s, siocgifmtu, &req) < 0)
{
continue;
}
@ -510,7 +520,7 @@ namespace libtorrent
memset(&req, 0, sizeof(req));
// -1 to leave a null terminator
strncpy(req.ifr_name, item.ifr_name, IF_NAMESIZE - 1);
if (ioctl(s, SIOCGIFMTU, &req) < 0)
if (ioctl(s, siocgifmtu, &req) < 0)
{
ec = error_code(errno, boost::asio::error::system_category);
close(s);
@ -690,6 +700,7 @@ namespace libtorrent
std::vector<ip_route> enum_routes(io_service& ios, error_code& ec)
{
std::vector<ip_route> ret;
TORRENT_UNUSED(ios);
#ifdef TORRENT_BUILD_SIMULATOR

View File

@ -69,7 +69,7 @@ namespace libtorrent
FileIdBothDirectoryInfo,
FileIdBothDirectoryRestartInfo,
FileIoPriorityHintInfo,
FileRemoteProtocolInfo,
FileRemoteProtocolInfo,
MaximumFileInfoByHandleClass
} FILE_INFO_BY_HANDLE_CLASS, *PFILE_INFO_BY_HANDLE_CLASS;
@ -102,7 +102,7 @@ namespace libtorrent
SetFileInformationByHandle = (SetFileInformationByHandle_t)GetProcAddress(kernel32, "SetFileInformationByHandle");
if (SetFileInformationByHandle == NULL)
{
{
failed_kernel_load = true;
return;
}
@ -132,7 +132,8 @@ namespace libtorrent
#if TORRENT_USE_ASSERTS
// we're not allowed to open a file
// from a deleted storage!
TORRENT_ASSERT(std::find(m_deleted_storages.begin(), m_deleted_storages.end(), std::make_pair(fs.name(), (void const*)&fs))
TORRENT_ASSERT(std::find(m_deleted_storages.begin(), m_deleted_storages.end()
, std::make_pair(fs.name(), static_cast<void const*>(&fs)))
== m_deleted_storages.end());
#endif
@ -211,7 +212,7 @@ namespace libtorrent
file_handle file_ptr = e.file_ptr;
// the file is not in our cache
if ((int)m_files.size() >= m_size)
if (int(m_files.size()) >= m_size)
{
// the file cache is at its maximum size, close
// the least recently used (lru) file from it
@ -226,7 +227,7 @@ namespace libtorrent
file_set::const_iterator start = m_files.lower_bound(std::make_pair(st, 0));
file_set::const_iterator end = m_files.upper_bound(std::make_pair(st, INT_MAX));
for (file_set::const_iterator i = start; i != end; ++i)
{
pool_file_status s;

View File

@ -39,6 +39,10 @@ POSSIBILITY OF SUCH DAMAGE.
#if TORRENT_USE_RLIMIT
#include <sys/resource.h>
// capture this here where warnings are disabled (the macro generates warnings)
const rlim_t rlimit_as = RLIMIT_AS;
const rlim_t rlim_infinity = RLIM_INFINITY;
#endif
#ifdef TORRENT_BSD
@ -93,7 +97,7 @@ namespace libtorrent
if (ret > 0)
{
struct rlimit r;
if (getrlimit(RLIMIT_AS, &r) == 0 && r.rlim_cur != RLIM_INFINITY)
if (getrlimit(rlimit_as, &r) == 0 && r.rlim_cur != rlim_infinity)
{
if (ret > r.rlim_cur)
ret = r.rlim_cur;

View File

@ -60,6 +60,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include <valgrind/memcheck.h>
#endif
#if TORRENT_USE_RLIMIT
// capture this here where warnings are disabled (the macro generates warnings)
const rlim_t rlim_infinity = RLIM_INFINITY;
#endif
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/peer_id.hpp"
@ -1820,8 +1825,6 @@ retry:
{
// this means we should open two listen sockets
// one for IPv4 and one for IPv6
const int retries = m_settings.get_int(settings_pack::max_retry_port_bind);
listen_socket_t s = setup_listener("0.0.0.0", true
, m_listen_interface.port()
, flags, ec);
@ -1947,8 +1950,6 @@ retry:
#ifdef TORRENT_USE_OPENSSL
if (m_settings.get_int(settings_pack::ssl_listen))
{
int retries = 10;
listen_socket_t s = setup_listener(device, address_family
, m_settings.get_int(settings_pack::ssl_listen)
, flags | open_ssl_socket, ec);
@ -2896,8 +2897,7 @@ retry:
#ifndef TORRENT_DISABLE_LOGGING
session_log("*** TICK TIMER FAILED %s", e.message().c_str());
#endif
::abort();
return;
std::abort();
}
#if defined TORRENT_ASIO_DEBUGGING
@ -4550,15 +4550,15 @@ retry:
{
int pos;
error_code err;
bdecode_node tmp;
bdecode_node root;
bdecode_node info;
#ifndef TORRENT_DISABLE_LOGGING
session_log("adding magnet link with resume data");
#endif
if (bdecode(&params.resume_data[0], &params.resume_data[0]
+ params.resume_data.size(), tmp, err, &pos) == 0
&& tmp.type() == bdecode_node::dict_t
&& (info = tmp.dict_find_dict("info")))
+ params.resume_data.size(), root, err, &pos) == 0
&& root.type() == bdecode_node::dict_t
&& (info = root.dict_find_dict("info")))
{
#ifndef TORRENT_DISABLE_LOGGING
session_log("found metadata in resume data");
@ -6128,7 +6128,7 @@ retry:
#if TORRENT_USE_RLIMIT
rlimit l;
if (getrlimit(RLIMIT_NOFILE, &l) == 0
&& l.rlim_cur != RLIM_INFINITY)
&& l.rlim_cur != rlim_infinity)
{
m_settings.set_int(settings_pack::connections_limit
, l.rlim_cur - m_settings.get_int(settings_pack::file_pool_size));

View File

@ -495,19 +495,19 @@ namespace libtorrent
// special case for deprecated float values
int val = current.get_int(settings_pack::share_ratio_limit);
if (s.share_ratio_limit != float(val) / 100.f)
if (fabs(s.share_ratio_limit - float(val) / 100.f) > 0.001f)
p->set_int(settings_pack::share_ratio_limit, s.share_ratio_limit * 100);
val = current.get_int(settings_pack::seed_time_ratio_limit);
if (s.seed_time_ratio_limit != float(val) / 100.f)
if (fabs(s.seed_time_ratio_limit - float(val) / 100.f) > 0.001f)
p->set_int(settings_pack::seed_time_ratio_limit, s.seed_time_ratio_limit * 100);
val = current.get_int(settings_pack::peer_turnover);
if (s.peer_turnover != float(val) / 100.f)
if (fabs(s.peer_turnover - float(val) / 100.f) > 0.001)
p->set_int(settings_pack::peer_turnover, s.peer_turnover * 100);
val = current.get_int(settings_pack::peer_turnover_cutoff);
if (s.peer_turnover_cutoff != float(val) / 100.f)
if (fabs(s.peer_turnover_cutoff - float(val) / 100.f) > 0.001)
p->set_int(settings_pack::peer_turnover_cutoff, s.peer_turnover_cutoff * 100);
return p;

View File

@ -68,9 +68,8 @@ namespace
using namespace std;
u32 a, b, c, d, e;
CHAR64LONG16* block;
u8 workspace[64];
block = (CHAR64LONG16*)workspace;
CHAR64LONG16 workspace;
CHAR64LONG16* block = &workspace;
memcpy(block, buffer, 64);
// Copy context->state[] to working vars
@ -213,9 +212,9 @@ void SHA1_final(u8* digest, sha_ctx* context)
>> ((3-(i & 3)) * 8) ) & 255);
}
SHA1_update(context, (u8 const*)"\200", 1);
SHA1_update(context, reinterpret_cast<u8 const*>("\200"), 1);
while ((context->count[0] & 504) != 448)
SHA1_update(context, (u8 const*)"\0", 1);
SHA1_update(context, reinterpret_cast<u8 const*>("\0"), 1);
SHA1_update(context, finalcount, 8); // Should cause a SHA1transform()
for (u32 i = 0; i < 20; ++i)
@ -226,7 +225,7 @@ void SHA1_final(u8* digest, sha_ctx* context)
}
} // libtorrent namespace
/************************************************************
-----------------

View File

@ -4500,7 +4500,7 @@ namespace libtorrent
for (std::vector<torrent_peer*>::iterator i = downloaders.begin()
, end(downloaders.end()); i != end; ++i)
{
torrent_peer* p = (torrent_peer*)*i;
torrent_peer* p = *i;
if (p && p->connection)
{
peer_connection* peer = static_cast<peer_connection*>(p->connection);
@ -4552,7 +4552,7 @@ namespace libtorrent
std::vector<pending_block> const& dq = p->download_queue();
std::vector<pending_block> const& rq = p->request_queue();
for (std::vector<pending_block>::const_iterator k = dq.begin()
, end(dq.end()); k != end; ++k)
, end2(dq.end()); k != end2; ++k)
{
if (k->timed_out || k->not_wanted) continue;
if (int(k->block.piece_index) != j->piece) continue;
@ -4560,7 +4560,7 @@ namespace libtorrent
, p->picker_options());
}
for (std::vector<pending_block>::const_iterator k = rq.begin()
, end(rq.end()); k != end; ++k)
, end2(rq.end()); k != end2; ++k)
{
if (int(k->block.piece_index) != j->piece) continue;
m_picker->mark_as_downloading(k->block, p->peer_info_struct()
@ -4668,14 +4668,14 @@ namespace libtorrent
if (m_suggested_pieces.empty()
|| num_peers < m_suggested_pieces[m_suggested_pieces.size()-1].num_peers - 1)
{
suggest_piece_t p;
p.piece_index = index;
p.num_peers = num_peers;
suggest_piece_t sp;
sp.piece_index = index;
sp.num_peers = num_peers;
typedef std::vector<suggest_piece_t>::iterator iter;
std::pair<iter, iter> range = std::equal_range(
m_suggested_pieces.begin(), m_suggested_pieces.end(), p);
m_suggested_pieces.begin(), m_suggested_pieces.end(), sp);
// make sure this piece isn't already in the suggested set.
// if it is, just ignore it
@ -4683,7 +4683,7 @@ namespace libtorrent
, boost::bind(&suggest_piece_t::piece_index, _1) == index);
if (i != range.second) return;
m_suggested_pieces.insert(range.second, p);
m_suggested_pieces.insert(range.second, sp);
if (m_suggested_pieces.size() > 0)
m_suggested_pieces.pop_back();
@ -4770,10 +4770,10 @@ namespace libtorrent
// TODO: really, we should just keep the picker around
// in this case to maintain the availability counters
p.num_peers = 0;
for (const_peer_iterator i = m_connections.begin()
, end(m_connections.end()); i != end; ++i)
for (const_peer_iterator j = m_connections.begin()
, end2(m_connections.end()); j != end2; ++j)
{
peer_connection* peer = *i;
peer_connection* peer = *j;
if (peer->has_piece(p.piece_index)) ++p.num_peers;
}
}
@ -5029,7 +5029,7 @@ namespace libtorrent
std::vector<pending_block> dq = p->download_queue();
for (std::vector<pending_block>::iterator k = dq.begin()
, end(dq.end()); k != end; ++k)
, end2(dq.end()); k != end2; ++k)
{
if (time_critical.count(k->block.piece_index)) continue;
if (k->not_wanted || k->timed_out) continue;
@ -5038,7 +5038,7 @@ namespace libtorrent
std::vector<pending_block> rq = p->request_queue();
for (std::vector<pending_block>::const_iterator k = rq.begin()
, end(rq.end()); k != end; ++k)
, end2(rq.end()); k != end2; ++k)
{
if (time_critical.count(k->block.piece_index)) continue;
p->cancel_request(k->block, true);
@ -5117,9 +5117,10 @@ namespace libtorrent
p.deadline = deadline;
p.peers = 0;
p.piece = piece;
std::vector<time_critical_piece>::iterator i = std::upper_bound(m_time_critical_pieces.begin()
std::vector<time_critical_piece>::iterator critical_piece_it
= std::upper_bound(m_time_critical_pieces.begin()
, m_time_critical_pieces.end(), p);
m_time_critical_pieces.insert(i, p);
m_time_critical_pieces.insert(critical_piece_it, p);
// just in case this piece had priority 0
int prev_prio = m_picker->piece_priority(piece);
@ -5139,9 +5140,9 @@ namespace libtorrent
for (std::vector<torrent_peer*>::iterator i = downloaders.begin()
, end(downloaders.end()); i != end; ++i, ++block)
{
torrent_peer* p = *i;
if (p == 0 || p->connection == 0) continue;
peer_connection* peer = static_cast<peer_connection*>(p->connection);
torrent_peer* tp = *i;
if (tp == 0 || tp->connection == 0) continue;
peer_connection* peer = static_cast<peer_connection*>(tp->connection);
peer->make_time_critical(piece_block(piece, block));
}
}
@ -8090,6 +8091,8 @@ namespace libtorrent
, !m_allow_peers && m_auto_managed && !m_abort);
}
namespace {
char const* list_name(int idx)
{
#define TORRENT_LIST_NAME(n) case aux::session_interface:: n: return #n;
@ -8109,6 +8112,8 @@ namespace libtorrent
return "";
}
} // anonymous namespace
void torrent::update_list(int list, bool in)
{
link& l = m_links[list];
@ -8766,12 +8771,18 @@ namespace libtorrent
if (p.peer_info_struct() && p.peer_info_struct()->seed)
++seeds;
for (std::vector<pending_block>::const_iterator i = p.request_queue().begin()
, end(p.request_queue().end()); i != end; ++i)
if (!i->not_wanted && !i->timed_out) ++num_requests[i->block];
for (std::vector<pending_block>::const_iterator i = p.download_queue().begin()
, end(p.download_queue().end()); i != end; ++i)
if (!i->not_wanted && !i->timed_out) ++num_requests[i->block];
for (std::vector<pending_block>::const_iterator j = p.request_queue().begin()
, end(p.request_queue().end()); j != end; ++j)
{
if (!j->not_wanted && !j->timed_out) ++num_requests[j->block];
}
for (std::vector<pending_block>::const_iterator j = p.download_queue().begin()
, end(p.download_queue().end()); j != end; ++j)
{
if (!j->not_wanted && !j->timed_out) ++num_requests[j->block];
}
if (!p.is_choked() && !p.ignore_unchoke_slots()) ++num_uploads;
torrent* associated_torrent = p.associated_torrent().lock().get();
if (associated_torrent != this && associated_torrent != 0)
@ -8800,23 +8811,23 @@ namespace libtorrent
fprintf(stderr, "picker count discrepancy: "
"picker: %d != peerlist: %d\n", picker_count, count);
for (const_peer_iterator i = this->begin(); i != this->end(); ++i)
for (const_peer_iterator j = this->begin(); j != this->end(); ++j)
{
peer_connection const& p = *(*i);
peer_connection const& p = *(*j);
fprintf(stderr, "peer: %s\n", print_endpoint(p.remote()).c_str());
for (std::vector<pending_block>::const_iterator i = p.request_queue().begin()
, end2(p.request_queue().end()); i != end2; ++i)
for (std::vector<pending_block>::const_iterator k = p.request_queue().begin()
, end2(p.request_queue().end()); k != end2; ++k)
{
fprintf(stderr, " rq: (%d, %d) %s %s %s\n", i->block.piece_index
, i->block.block_index, i->not_wanted ? "not-wanted" : ""
, i->timed_out ? "timed-out" : "", i->busy ? "busy": "");
fprintf(stderr, " rq: (%d, %d) %s %s %s\n", k->block.piece_index
, k->block.block_index, k->not_wanted ? "not-wanted" : ""
, k->timed_out ? "timed-out" : "", k->busy ? "busy": "");
}
for (std::vector<pending_block>::const_iterator i = p.download_queue().begin()
, end2(p.download_queue().end()); i != end2; ++i)
for (std::vector<pending_block>::const_iterator k = p.download_queue().begin()
, end2(p.download_queue().end()); k != end2; ++k)
{
fprintf(stderr, " dq: (%d, %d) %s %s %s\n", i->block.piece_index
, i->block.block_index, i->not_wanted ? "not-wanted" : ""
, i->timed_out ? "timed-out" : "", i->busy ? "busy": "");
fprintf(stderr, " dq: (%d, %d) %s %s %s\n", k->block.piece_index
, k->block.block_index, k->not_wanted ? "not-wanted" : ""
, k->timed_out ? "timed-out" : "", k->busy ? "busy": "");
}
}
TORRENT_ASSERT(false);