fixed shorten-64-to-32 warnings for clang

This commit is contained in:
Alden Torres 2016-12-09 08:23:54 -05:00 committed by Arvid Norberg
parent 7266b0b360
commit e73435a77b
10 changed files with 37 additions and 38 deletions

View File

@ -246,7 +246,6 @@ rule warnings ( properties * )
# enable these warnings again, once the other ones are dealt with
result += <cflags>-Wno-weak-vtables ;
result += <cflags>-Wno-sign-conversion ;
result += <cflags>-Wno-shorten-64-to-32 ;
}
if <toolset>gcc in $(properties)

View File

@ -114,7 +114,7 @@ namespace libtorrent
TORRENT_ASSERT(is_single_thread());
if (m_vec.empty()) return 0;
buffer_t& b = m_vec.back();
return b.size - b.used_size - (b.start - b.buf);
return b.size - b.used_size - int(b.start - b.buf);
}
// tries to copy the given buffer to the end of the

View File

@ -91,7 +91,7 @@ namespace libtorrent
char buf[MAX_SYMLINK_PATH];
std::string f = convert_to_native(path);
int char_read = readlink(f.c_str(), buf, MAX_SYMLINK_PATH);
int char_read = int(readlink(f.c_str(), buf, MAX_SYMLINK_PATH));
if (char_read < 0) return "";
if (char_read < MAX_SYMLINK_PATH) buf[char_read] = 0;
else buf[0] = 0;

View File

@ -432,7 +432,7 @@ namespace libtorrent
phys_ram = 1 * gb;
}
result += phys_ram / 10;
m_max_use = result / m_block_size;
m_max_use = int(result / m_block_size);
}
#ifdef _MSC_VER
@ -562,7 +562,7 @@ namespace libtorrent
{
TORRENT_ASSERT(buf >= m_cache_pool);
TORRENT_ASSERT(buf < m_cache_pool + std::uint64_t(m_max_use) * 0x4000);
int slot_index = (buf - m_cache_pool) / 0x4000;
int slot_index = int((buf - m_cache_pool) / 0x4000);
m_free_list.push_back(slot_index);
#if defined MADV_FREE
// tell the virtual memory system that we don't actually care

View File

@ -175,7 +175,7 @@ namespace libtorrent { namespace
if ((nl_hdr->nlmsg_flags & NLM_F_MULTI) == 0) break;
} while((nl_hdr->nlmsg_seq != seq) || (nl_hdr->nlmsg_pid != pid));
} while((int(nl_hdr->nlmsg_seq) != seq) || (int(nl_hdr->nlmsg_pid) != pid));
return msg_len;
}
@ -650,7 +650,7 @@ namespace libtorrent
#endif
SOCKET s = socket(AF_INET, SOCK_DGRAM, 0);
if (s == SOCKET_ERROR)
if (int(s) == SOCKET_ERROR)
{
ec = error_code(WSAGetLastError(), system_category());
return ret;
@ -1005,7 +1005,7 @@ namespace libtorrent
int res = GetIpForwardTable2(AF_UNSPEC, &routes);
if (res == NO_ERROR)
{
for (int i = 0; i < routes->NumEntries; ++i)
for (int i = 0; i < int(routes->NumEntries); ++i)
{
ip_route r;
r.gateway = sockaddr_to_address((const sockaddr*)&routes->Table[i].NextHop);
@ -1060,7 +1060,7 @@ namespace libtorrent
if (GetIpForwardTable(routes, &out_buf_size, FALSE) == NO_ERROR)
{
for (int i = 0; i < routes->dwNumEntries; ++i)
for (int i = 0; i < int(routes->dwNumEntries); ++i)
{
ip_route r;
r.destination = inaddr_to_address((in_addr const*)&routes->table[i].dwForwardDest);

View File

@ -492,7 +492,7 @@ namespace libtorrent
for (const wchar_t* i = &s[0]; i < end;)
{
char c[10];
TORRENT_ASSERT(sizeof(c) >= MB_CUR_MAX);
TORRENT_ASSERT(sizeof(c) >= std::size_t(MB_CUR_MAX));
int const result = std::wctomb(c, *i);
if (result > 0)
{

View File

@ -158,7 +158,7 @@ namespace
// windows only lets us wait for 64 handles at a time, so this function makes
// sure we wait for all of them, partially in sequence
int wait_for_multiple_objects(int num_handles, HANDLE* h)
DWORD wait_for_multiple_objects(int num_handles, HANDLE* h)
{
int batch_size = (std::min)(num_handles, MAXIMUM_WAIT_OBJECTS);
while (WaitForMultipleObjects(batch_size, h, TRUE, INFINITE) != WAIT_FAILED)
@ -1771,10 +1771,10 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
#elif TORRENT_USE_PREAD
int ret = 0;
std::int64_t ret = 0;
for (auto i : bufs)
{
int tmp_ret = f(fd, i.iov_base, i.iov_len, file_offset);
std::int64_t tmp_ret = f(fd, i.iov_base, i.iov_len, file_offset);
if (tmp_ret < 0)
{
#ifdef TORRENT_WINDOWS
@ -1873,9 +1873,9 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
}
#if TORRENT_USE_PREAD
int ret = iov(&::pread, native_handle(), file_offset, tmp_bufs, ec);
std::int64_t ret = iov(&::pread, native_handle(), file_offset, tmp_bufs, ec);
#else
int ret = iov(&::read, native_handle(), file_offset, tmp_bufs, ec);
std::int64_t ret = iov(&::read, native_handle(), file_offset, tmp_bufs, ec);
#endif
if ((flags & file::coalesce_buffers))
@ -1928,9 +1928,9 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
}
#if TORRENT_USE_PREAD
int ret = iov(&::pwrite, native_handle(), file_offset, bufs, ec);
std::int64_t ret = iov(&::pwrite, native_handle(), file_offset, bufs, ec);
#else
int ret = iov(&::write, native_handle(), file_offset, bufs, ec);
std::int64_t ret = iov(&::write, native_handle(), file_offset, bufs, ec);
#endif
if (flags & file::coalesce_buffers)

View File

@ -151,13 +151,13 @@ namespace libtorrent { namespace aux
int const piece_size = fs.piece_length();
std::int64_t off = std::int64_t(index) * piece_size;
int file_index = fs.file_index_at_offset(off);
int size = fs.piece_size(index);
std::int64_t size = fs.piece_size(index);
for (; size > 0; ++file_index)
{
std::int64_t file_offset = off - fs.file_offset(file_index);
TORRENT_ASSERT(file_index != fs.num_files());
TORRENT_ASSERT(file_offset <= fs.file_size(file_index));
int add = (std::min)(fs.file_size(file_index)
std::int64_t add = (std::min)(fs.file_size(file_index)
- file_offset, std::int64_t(size));
m_file_progress[file_index] += add;

View File

@ -127,7 +127,7 @@ namespace libtorrent
// split the string into the leaf filename
// and the branch path
branch_path = path.c_str();
branch_len = leaf - path.c_str();
branch_len = int(leaf - path.c_str());
// trim trailing slashes
if (branch_len > 0 && branch_path[branch_len - 1] == TORRENT_SEPARATOR)
@ -176,7 +176,7 @@ namespace libtorrent
else
{
// yes we do. use it
e.path_index = p.base() - m_paths.begin() - 1;
e.path_index = int(p.base() - m_paths.begin() - 1);
}
if (set_name) e.set_name(leaf);
}
@ -415,7 +415,7 @@ namespace libtorrent
TORRENT_ASSERT(file_iter != m_files.begin());
--file_iter;
return file_iter - m_files.begin();
return int(file_iter - m_files.begin());
}
char const* file_storage::file_name_ptr(int index) const
@ -446,7 +446,7 @@ namespace libtorrent
// in case the size is past the end, fix it up
if (std::int64_t(target.offset + size) > m_total_size)
size = m_total_size - target.offset;
size = int(m_total_size - target.offset);
auto file_iter = std::upper_bound(
m_files.begin(), m_files.end(), target, compare_file_offset);
@ -461,7 +461,7 @@ namespace libtorrent
if (file_offset < std::int64_t(file_iter->size))
{
file_slice f;
f.file_index = file_iter - m_files.begin();
f.file_index = int(file_iter - m_files.begin());
f.offset = file_offset
#ifndef TORRENT_NO_DEPRECATE
+ file_base_deprecated(f.file_index)
@ -854,7 +854,7 @@ namespace libtorrent
sha1_hash file_storage::hash(internal_file_entry const& fe) const
{
int index = &fe - &m_files[0];
int index = int(&fe - &m_files[0]);
if (index >= int(m_file_hashes.size())) return sha1_hash(nullptr);
return sha1_hash(m_file_hashes[index]);
}
@ -867,21 +867,21 @@ namespace libtorrent
time_t file_storage::mtime(internal_file_entry const& fe) const
{
int index = &fe - &m_files[0];
int index = int(&fe - &m_files[0]);
if (index >= int(m_mtime.size())) return 0;
return m_mtime[index];
}
int file_storage::file_index(internal_file_entry const& fe) const
{
int index = &fe - &m_files[0];
int index = int(&fe - &m_files[0]);
TORRENT_ASSERT_PRECOND(index >= 0 && index < int(m_files.size()));
return index;
}
void file_storage::set_file_base(internal_file_entry const& fe, std::int64_t off)
{
int index = &fe - &m_files[0];
int index = int(&fe - &m_files[0]);
TORRENT_ASSERT_PRECOND(index >= 0 && index < int(m_files.size()));
if (int(m_file_base.size()) <= index) m_file_base.resize(index + 1, 0);
m_file_base[index] = off;
@ -889,7 +889,7 @@ namespace libtorrent
std::int64_t file_storage::file_base(internal_file_entry const& fe) const
{
int index = &fe - &m_files[0];
int index = int(&fe - &m_files[0]);
if (index >= int(m_file_base.size())) return 0;
return m_file_base[index];
}
@ -897,7 +897,7 @@ namespace libtorrent
std::string file_storage::file_path(internal_file_entry const& fe
, std::string const& save_path) const
{
int const index = &fe - &m_files[0];
int const index = int(&fe - &m_files[0]);
return file_path(index, save_path);
}
@ -922,7 +922,7 @@ namespace libtorrent
}
file_entry file_storage::at(file_storage::iterator i) const
{ return at_deprecated(i - m_files.begin()); }
{ return at_deprecated(int(i - m_files.begin())); }
#endif // TORRENT_NO_DEPRECATE
void file_storage::reorder_file(int const index, int const dst)
@ -990,8 +990,8 @@ namespace libtorrent
if (best_match != i)
{
int const index = best_match - m_files.begin();
int const cur_index = i - m_files.begin();
int const index = int(best_match - m_files.begin());
int const cur_index = int(i - m_files.begin());
reorder_file(index, cur_index);
i = m_files.begin() + cur_index;
}
@ -1028,8 +1028,8 @@ namespace libtorrent
// look for files <= pad_size, which never is greater than
// alignment
TORRENT_ASSERT(best_match != i);
int index = best_match - m_files.begin();
int cur_index = i - m_files.begin();
int index = int(best_match - m_files.begin());
int cur_index = int(i - m_files.begin());
reorder_file(index, cur_index);
i = m_files.begin() + cur_index;
i->offset = off;
@ -1081,7 +1081,7 @@ namespace libtorrent
, std::int64_t& offset
, int& pad_file_counter)
{
int const cur_index = i - m_files.begin();
int const cur_index = int(i - m_files.begin());
int const index = int(m_files.size());
m_files.push_back(internal_file_entry());
++m_num_files;
@ -1135,7 +1135,7 @@ namespace libtorrent
// contained within the last file.
int const end_piece = (file == fs.num_files() - 1)
? fs.num_pieces()
: (range.piece * piece_size + range.start + file_size + 1) / piece_size;
: int((range.piece * piece_size + range.start + file_size + 1) / piece_size);
return std::make_tuple(begin_piece, end_piece);
}

View File

@ -60,7 +60,7 @@ namespace libtorrent
{
std::array<peer_class_t, 15>::iterator i = std::find(m_class.begin()
, m_class.begin() + m_size, c);
int idx = i - m_class.begin();
int idx = int(i - m_class.begin());
if (idx == m_size) return; // not found
if (idx < m_size - 1)
{