From fdfe69f414a47dd294677fa223e0798f14669ab7 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 3 Aug 2016 00:35:40 -0400 Subject: [PATCH] fixed warnings and compilation issues (#980) fixed warnings and compilation issues --- .../libtorrent/aux_/disable_warnings_push.hpp | 2 +- include/libtorrent/bitfield.hpp | 1 - include/libtorrent/config.hpp | 4 +- include/libtorrent/error_code.hpp | 1 - include/libtorrent/socket.hpp | 3 -- include/libtorrent/torrent_info.hpp | 1 - include/libtorrent/utp_stream.hpp | 2 + src/bitfield.cpp | 3 +- src/enum_net.cpp | 38 ++++++++++++------- src/error_code.cpp | 4 -- src/file.cpp | 8 ---- src/peer_connection_handle.cpp | 1 + src/utp_stream.cpp | 20 +++++----- src/xml_parse.cpp | 1 + 14 files changed, 42 insertions(+), 47 deletions(-) diff --git a/include/libtorrent/aux_/disable_warnings_push.hpp b/include/libtorrent/aux_/disable_warnings_push.hpp index c137ee1da..e0cb444bd 100644 --- a/include/libtorrent/aux_/disable_warnings_push.hpp +++ b/include/libtorrent/aux_/disable_warnings_push.hpp @@ -80,6 +80,7 @@ POSSIBILITY OF SUCH DAMAGE. #pragma clang diagnostic ignored "-Wgnu-folding-constant" #pragma clang diagnostic ignored "-Wdouble-promotion" #pragma clang diagnostic ignored "-Wfloat-equal" +#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef _MSC_VER @@ -87,4 +88,3 @@ POSSIBILITY OF SUCH DAMAGE. // warning C4005: macro redefinition #pragma warning( disable : 4005 ) #endif - diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index 3db34a408..53153fedf 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -255,4 +255,3 @@ namespace libtorrent } #endif // TORRENT_BITFIELD_HPP_INCLUDED - diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 2a0378567..f30afcd98 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -167,7 +167,7 @@ POSSIBILITY OF SUCH DAMAGE. #elif defined __linux__ #define TORRENT_LINUX -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30) && !defined __ANDROID__ # define TORRENT_USE_PREADV 1 # define TORRENT_USE_PREAD 0 #else @@ -183,8 +183,6 @@ POSSIBILITY OF SUCH DAMAGE. // ===== ANDROID ===== (almost linux, sort of) #if defined __ANDROID__ -#define TORRENT_USE_PREADV 0 -#define TORRENT_USE_PREAD 1 #define TORRENT_ANDROID 1 #define TORRENT_HAS_FALLOCATE 0 #define TORRENT_USE_ICONV 0 diff --git a/include/libtorrent/error_code.hpp b/include/libtorrent/error_code.hpp index 66b4bfccd..72ec0c0fd 100644 --- a/include/libtorrent/error_code.hpp +++ b/include/libtorrent/error_code.hpp @@ -46,7 +46,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include #include "libtorrent/aux_/disable_warnings_pop.hpp" diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index 1f1067778..c7b62a9cf 100644 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -50,8 +50,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#include - #include #include #include @@ -194,4 +192,3 @@ namespace libtorrent } #endif // TORRENT_SOCKET_HPP_INCLUDED - diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index df8b1c743..8d2473ec7 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -49,7 +49,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/time.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/copy_ptr.hpp" -#include "libtorrent/socket.hpp" #include "libtorrent/sha1_hash.hpp" #include "libtorrent/file_storage.hpp" diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index 90599b366..84c24f39d 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -63,6 +63,8 @@ namespace libtorrent #endif #if TORRENT_UTP_LOG + TORRENT_FORMAT(1, 2) + void utp_log(char const* fmt, ...); TORRENT_EXPORT bool is_utp_stream_logging(); // This function should be used at the very beginning and very end of your program. diff --git a/src/bitfield.cpp b/src/bitfield.cpp index b9842c9dd..1b8703ea2 100644 --- a/src/bitfield.cpp +++ b/src/bitfield.cpp @@ -90,7 +90,7 @@ namespace libtorrent { for (int i = 1; i < words + 1; ++i) { - uint8x8_t const in_val = vld1_u8((unsigned char *) &m_buf[i]); + uint8x8_t const in_val = vld1_u8(reinterpret_cast(&m_buf[i])); uint8x8_t const cnt8x8_val = vcnt_u8(in_val); uint16x4_t const cnt16x4_val = vpaddl_u8(cnt8x8_val); uint32x2_t const cnt32x2_val = vpaddl_u16(cnt16x4_val); @@ -191,4 +191,3 @@ namespace libtorrent TORRENT_ASSERT(size() == bits); } } - diff --git a/src/enum_net.cpp b/src/enum_net.cpp index d2600e699..801726550 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -159,7 +159,7 @@ namespace libtorrent { namespace int read_len = recv(sock, buf, bufsize - msg_len, 0); if (read_len < 0) return -1; - nl_hdr = (nlmsghdr*)buf; + nl_hdr = reinterpret_cast(buf); if ((NLMSG_OK(nl_hdr, read_len) == 0) || (nl_hdr->nlmsg_type == NLMSG_ERROR)) return -1; @@ -177,7 +177,7 @@ namespace libtorrent { namespace bool parse_route(int s, nlmsghdr* nl_hdr, ip_route* rt_info) { - rtmsg* rt_msg = (rtmsg*)NLMSG_DATA(nl_hdr); + rtmsg* rt_msg = reinterpret_cast(NLMSG_DATA(nl_hdr)); if((rt_msg->rtm_family != AF_INET && rt_msg->rtm_family != AF_INET6) || (rt_msg->rtm_table != RT_TABLE_MAIN && rt_msg->rtm_table != RT_TABLE_LOCAL)) @@ -185,40 +185,47 @@ namespace libtorrent { namespace int if_index = 0; int rt_len = RTM_PAYLOAD(nl_hdr); - for (rtattr* rt_attr = (rtattr*)RTM_RTA(rt_msg); +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wcast-align" +#endif + for (rtattr* rt_attr = reinterpret_cast(RTM_RTA(rt_msg)); RTA_OK(rt_attr,rt_len); rt_attr = RTA_NEXT(rt_attr,rt_len)) { switch(rt_attr->rta_type) { case RTA_OIF: - if_index = *(int*)RTA_DATA(rt_attr); + if_index = *reinterpret_cast(RTA_DATA(rt_attr)); break; case RTA_GATEWAY: #if TORRENT_USE_IPV6 if (rt_msg->rtm_family == AF_INET6) { - rt_info->gateway = inaddr6_to_address((in6_addr*)RTA_DATA(rt_attr)); + rt_info->gateway = inaddr6_to_address(reinterpret_cast(RTA_DATA(rt_attr))); } else #endif { - rt_info->gateway = inaddr_to_address((in_addr*)RTA_DATA(rt_attr)); + rt_info->gateway = inaddr_to_address(reinterpret_cast(RTA_DATA(rt_attr))); } break; case RTA_DST: #if TORRENT_USE_IPV6 if (rt_msg->rtm_family == AF_INET6) { - rt_info->destination = inaddr6_to_address((in6_addr*)RTA_DATA(rt_attr)); + rt_info->destination = inaddr6_to_address(reinterpret_cast(RTA_DATA(rt_attr))); } else #endif { - rt_info->destination = inaddr_to_address((in_addr*)RTA_DATA(rt_attr)); + rt_info->destination = inaddr_to_address(reinterpret_cast(RTA_DATA(rt_attr))); } break; } } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif if_indextoname(if_index, rt_info->name); ifreq req; @@ -493,7 +500,7 @@ namespace libtorrent // make sure the buffer is aligned to hold ifreq structs ifreq buf[40]; ifc.ifc_len = sizeof(buf); - ifc.ifc_buf = (char*)buf; + ifc.ifc_buf = reinterpret_cast(buf); if (ioctl(s, SIOCGIFCONF, &ifc) < 0) { ec = error_code(errno, system_category()); @@ -501,7 +508,7 @@ namespace libtorrent return ret; } - char *ifr = (char*)ifc.ifc_req; + char *ifr = reinterpret_cast(ifc.ifc_req); int remaining = ifc.ifc_len; while (remaining > 0) @@ -1084,7 +1091,7 @@ namespace libtorrent char msg[BUFSIZE]; memset(msg, 0, BUFSIZE); - nlmsghdr* nl_msg = (nlmsghdr*)msg; + nlmsghdr* nl_msg = reinterpret_cast(msg); nl_msg->nlmsg_len = NLMSG_LENGTH(sizeof(rtmsg)); nl_msg->nlmsg_type = RTM_GETROUTE; @@ -1113,11 +1120,18 @@ namespace libtorrent ec = error_code(errno, system_category()); return std::vector(); } +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wcast-align" +#endif for (; NLMSG_OK(nl_msg, len); nl_msg = NLMSG_NEXT(nl_msg, len)) { ip_route r; if (parse_route(s, nl_msg, &r)) ret.push_back(r); } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif close(s); close(sock); @@ -1148,5 +1162,3 @@ namespace libtorrent return std::string(); } } - - diff --git a/src/error_code.cpp b/src/error_code.cpp index 646e44618..11f96a740 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -30,12 +30,9 @@ POSSIBILITY OF SUCH DAMAGE. */ -#include - #include "libtorrent/config.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/string_util.hpp" // for to_string() -#include "libtorrent/aux_/escape_string.hpp" // for convert_to_native namespace libtorrent { @@ -332,4 +329,3 @@ namespace libtorrent } } - diff --git a/src/file.cpp b/src/file.cpp index 4ce722aa5..6d5beaf8b 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -118,14 +118,6 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef TORRENT_LINUX // linux specifics -#ifdef TORRENT_ANDROID -#include -#define statvfs statfs -#define fstatvfs fstatfs -#else -#include -#endif - #include #ifdef TORRENT_ANDROID #include diff --git a/src/peer_connection_handle.cpp b/src/peer_connection_handle.cpp index 3b3323d74..065bb0b8f 100644 --- a/src/peer_connection_handle.cpp +++ b/src/peer_connection_handle.cpp @@ -233,6 +233,7 @@ void peer_connection_handle::peer_log(peer_log_alert::direction_t direction #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wformat-nonliteral" +#pragma clang diagnostic ignored "-Wclass-varargs" #endif pc->peer_log(direction, event, fmt, v); #ifdef __clang__ diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 78a6b9f17..afef633c7 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -58,8 +58,8 @@ namespace libtorrent { #if TORRENT_UTP_LOG -char const* packet_type_names[] = { "ST_DATA", "ST_FIN", "ST_STATE", "ST_RESET", "ST_SYN" }; -char const* socket_state_names[] = { "NONE", "SYN_SENT", "CONNECTED", "FIN_SENT", "ERROR", "DELETE" }; +static char const* packet_type_names[] = { "ST_DATA", "ST_FIN", "ST_STATE", "ST_RESET", "ST_SYN" }; +static char const* socket_state_names[] = { "NONE", "SYN_SENT", "CONNECTED", "FIN_SENT", "ERROR", "DELETE" }; static struct utp_logger { @@ -3266,17 +3266,17 @@ bool utp_socket_impl::incoming_packet(span buf "\n" , static_cast(this) , sample - , float(delay / 1000.f) - , float(their_delay / 1000.f) - , float(int(m_sm->target_delay() - delay)) / 1000.f + , delay / 1000.0 + , their_delay / 1000.0 + , int(m_sm->target_delay() - delay) / 1000.0 , std::uint32_t(m_cwnd >> 16) , 0 , our_delay_base - , float(delay + their_delay) / 1000.f + , (delay + their_delay) / 1000.0 , m_sm->target_delay() / 1000 , acked_bytes , m_bytes_in_flight - , 0.f // float(scaled_gain) + , 0.0 // float(scaled_gain) , m_rtt.mean() , int((m_cwnd * 1000 / (m_rtt.mean()?m_rtt.mean():50)) >> 16) , 0 @@ -3485,9 +3485,9 @@ void utp_socket_impl::do_ledbat(const int acked_bytes, const int delay UTP_LOGV("%8p: do_ledbat delay:%d off_target: %d window_factor:%f target_factor:%f " "scaled_gain:%f cwnd:%d slow_start:%d\n" - , static_cast(this), delay, target_delay - delay, window_factor / float(1 << 16) - , delay_factor / float(1 << 16) - , scaled_gain / float(1 << 16), int(m_cwnd >> 16) + , static_cast(this), delay, target_delay - delay, window_factor / double(1 << 16) + , delay_factor / double(1 << 16) + , scaled_gain / double(1 << 16), int(m_cwnd >> 16) , int(m_slow_start)); // if scaled_gain + m_cwnd <= 0, set m_cwnd to 0 diff --git a/src/xml_parse.cpp b/src/xml_parse.cpp index 5f2626862..3bbdbce9d 100644 --- a/src/xml_parse.cpp +++ b/src/xml_parse.cpp @@ -30,6 +30,7 @@ POSSIBILITY OF SUCH DAMAGE. */ +#include #include "libtorrent/xml_parse.hpp" #include "libtorrent/string_util.hpp"