From eaf99aa42ba8d89240bd7bb0deb3d16f4bba18c3 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Sun, 18 Dec 2016 10:59:41 -0500 Subject: [PATCH] fixed more warnings of shorten-64-to-32 and sign-compare in android (#1425) fixed more warnings of -Wshorten-64-to-32 in android. changed file_status to use std::time and disable warnings of NLMSG_OK in clang --- include/libtorrent/file.hpp | 7 ++++--- include/libtorrent/file_storage.hpp | 6 +++--- src/enum_net.cpp | 12 +++++++++++- src/file.cpp | 4 ++-- src/file_storage.cpp | 2 +- src/read_resume_data.cpp | 6 +++--- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index 9a37d4561..48e0d25ff 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "libtorrent/config.hpp" #include "libtorrent/string_view.hpp" @@ -94,9 +95,9 @@ namespace libtorrent struct file_status { std::int64_t file_size; - std::uint64_t atime; - std::uint64_t mtime; - std::uint64_t ctime; + std::time_t atime; + std::time_t mtime; + std::time_t ctime; enum { #if defined TORRENT_WINDOWS fifo = 0x1000, // named pipe (fifo) diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index fbce89d68..dd6b621dd 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -129,8 +129,8 @@ namespace libtorrent string_view filename() const; enum { - name_is_owned = (1<<12)-1, - not_a_symlink = (1<<15)-1 + name_is_owned = (1 << 12) - 1, + not_a_symlink = (1 << 15) - 1 }; // the offset of this file inside the torrent @@ -283,7 +283,7 @@ namespace libtorrent void add_file_borrow(char const* filename, int filename_len , std::string const& path, std::int64_t file_size , std::uint32_t file_flags = 0, char const* filehash = 0 - , std::int64_t mtime = 0, string_view symlink_path = string_view()); + , std::time_t mtime = 0, string_view symlink_path = string_view()); void add_file(std::string const& path, std::int64_t file_size, int file_flags = 0 , std::time_t mtime = 0, string_view symlink_path = string_view()); diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 8fd3c2331..6ba8d9160 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -158,13 +158,21 @@ namespace libtorrent { namespace do { - int read_len = recv(sock, buf, bufsize - msg_len, 0); + int read_len = int(recv(sock, buf, bufsize - msg_len, 0)); if (read_len < 0) return -1; nl_hdr = reinterpret_cast(buf); +#ifdef __clang__ +#pragma clang diagnostic push +// NLMSG_OK uses signed/unsigned compare in the same expression +#pragma clang diagnostic ignored "-Wsign-compare" +#endif if ((NLMSG_OK(nl_hdr, read_len) == 0) || (nl_hdr->nlmsg_type == NLMSG_ERROR)) return -1; +#ifdef __clang__ +#pragma clang diagnostic pop +#endif if (nl_hdr->nlmsg_type == NLMSG_DONE) break; @@ -1120,6 +1128,8 @@ namespace libtorrent #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wcast-align" +// NLMSG_OK uses signed/unsigned compare in the same expression +#pragma clang diagnostic ignored "-Wsign-compare" #endif for (; NLMSG_OK(nl_msg, len); nl_msg = NLMSG_NEXT(nl_msg, len)) { diff --git a/src/file.cpp b/src/file.cpp index 3812ca10d..0640a28e0 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -662,14 +662,14 @@ namespace libtorrent char buffer[4096]; for (;;) { - int const num_read = read(infd, buffer, sizeof(buffer)); + int const num_read = int(read(infd, buffer, sizeof(buffer))); if (num_read == 0) break; if (num_read < 0) { ec.assign(errno, system_category()); break; } - int const num_written = write(outfd, buffer, num_read); + int const num_written = int(write(outfd, buffer, num_read)); if (num_written < num_read) { ec.assign(errno, system_category()); diff --git a/src/file_storage.cpp b/src/file_storage.cpp index b3151240f..e1ac2b714 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -549,7 +549,7 @@ namespace libtorrent void file_storage::add_file_borrow(char const* filename, int const filename_len , std::string const& path, std::int64_t const file_size , std::uint32_t const file_flags, char const* filehash - , std::int64_t const mtime, string_view symlink_path) + , std::time_t const mtime, string_view symlink_path) { TORRENT_ASSERT_PRECOND(file_size >= 0); if (!has_parent_path(path)) diff --git a/src/read_resume_data.cpp b/src/read_resume_data.cpp index 1f4928352..394eb1bea 100644 --- a/src/read_resume_data.cpp +++ b/src/read_resume_data.cpp @@ -117,7 +117,7 @@ namespace libtorrent ret.finished_time = int(rd.dict_find_int_value("finished_time")); ret.seeding_time = int(rd.dict_find_int_value("seeding_time")); - ret.last_seen_complete = rd.dict_find_int_value("last_seen_complete"); + ret.last_seen_complete = std::time_t(rd.dict_find_int_value("last_seen_complete")); // scrape data cache ret.num_complete = int(rd.dict_find_int_value("num_complete", -1)); @@ -156,8 +156,8 @@ namespace libtorrent } } - ret.added_time = rd.dict_find_int_value("added_time", 0); - ret.completed_time = rd.dict_find_int_value("completed_time", 0); + ret.added_time = std::time_t(rd.dict_find_int_value("added_time", 0)); + ret.completed_time = std::time_t(rd.dict_find_int_value("completed_time", 0)); // load file priorities except if the add_torrent_param file was set to // override resume data