fix some warnings

This commit is contained in:
Arvid Norberg 2018-09-19 11:32:18 -07:00 committed by Arvid Norberg
parent 8be9b3d976
commit 6724c1eec0
4 changed files with 33 additions and 24 deletions

View File

@ -36,19 +36,19 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/config.hpp>
#if !defined TORRENT_ABI_VERSION
#ifdef TORRENT_NO_DEPRECATE
#define TORRENT_ABI_VERSION 2
#else
#define TORRENT_ABI_VERSION 1
#endif
# ifdef TORRENT_NO_DEPRECATE
# define TORRENT_ABI_VERSION 2
# else
# define TORRENT_ABI_VERSION 1
# endif
#endif
#if TORRENT_ABI_VERSION >= 2
#define TORRENT_VERSION_NAMESPACE_2 inline namespace v1_2 {
#define TORRENT_VERSION_NAMESPACE_2_END }
# define TORRENT_VERSION_NAMESPACE_2 inline namespace v1_2 {
# define TORRENT_VERSION_NAMESPACE_2_END }
#else
#define TORRENT_VERSION_NAMESPACE_2
#define TORRENT_VERSION_NAMESPACE_2_END
# define TORRENT_VERSION_NAMESPACE_2
# define TORRENT_VERSION_NAMESPACE_2_END
#endif
// backwards compatibility with older versions of boost
@ -91,9 +91,9 @@ POSSIBILITY OF SUCH DAMAGE.
// only export this type if deprecated functions are enabled
#if TORRENT_ABI_VERSION >= 2
#define TORRENT_DEPRECATED_EXPORT TORRENT_EXTRA_EXPORT
# define TORRENT_DEPRECATED_EXPORT TORRENT_EXTRA_EXPORT
#else
#define TORRENT_DEPRECATED_EXPORT TORRENT_EXPORT
# define TORRENT_DEPRECATED_EXPORT TORRENT_EXPORT
#endif
#endif

View File

@ -89,7 +89,7 @@ namespace aux {
case portmap_action::none: return "none";
case portmap_action::add: return "add";
case portmap_action::del: return "delete";
};
}
return "";
}
}}

View File

@ -1992,6 +1992,7 @@ namespace {
TORRENT_ASSERT(num_pieces > 0);
constexpr std::uint8_t char_bit_mask = CHAR_BIT - 1;
constexpr std::uint8_t char_top_bit = 1 << (CHAR_BIT - 1);
const int packet_size = (num_pieces + char_bit_mask) / CHAR_BIT + 5;
@ -2013,14 +2014,14 @@ namespace {
{
std::memset(ptr, 0, aux::numeric_cast<std::size_t>(packet_size - 5));
piece_picker const& p = t->picker();
int mask = 0x80;
int mask = char_top_bit;
for (piece_index_t i(0); i < piece_index_t(num_pieces); ++i)
{
if (p.have_piece(i)) *ptr |= mask;
mask >>= 1;
if (mask == 0)
{
mask = 0x80;
mask = char_top_bit;
++ptr;
}
}
@ -2029,7 +2030,7 @@ namespace {
// add predictive pieces to the bitfield as well, since we won't
// announce them again
for (piece_index_t const p : t->predictive_pieces())
msg[5 + static_cast<int>(p) / CHAR_BIT] |= (0x80 >> (static_cast<int>(p) & char_bit_mask));
msg[5 + static_cast<int>(p) / CHAR_BIT] |= (char_top_bit >> (static_cast<int>(p) & char_bit_mask));
#ifndef TORRENT_DISABLE_LOGGING
if (should_log(peer_log_alert::outgoing_message))
@ -2039,7 +2040,7 @@ namespace {
bitfield_string.resize(n_pieces);
for (std::size_t k = 0; k < n_pieces; ++k)
{
if (msg[5 + int(k) / CHAR_BIT] & (0x80 >> (k % CHAR_BIT))) bitfield_string[k] = '1';
if (msg[5 + int(k) / CHAR_BIT] & (char_top_bit >> (k % CHAR_BIT))) bitfield_string[k] = '1';
else bitfield_string[k] = '0';
}
peer_log(peer_log_alert::outgoing_message, "BITFIELD"

View File

@ -679,6 +679,12 @@ namespace {
return false;
}
std::string print_string(std::string const& str)
{
if (is_binary(str)) return aux::to_hex(str);
else return str;
}
void add_indent(std::string& out, int const indent)
{
out.resize(out.size() + size_t(indent), ' ');
@ -697,20 +703,19 @@ namespace {
case string_t:
{
out += "'";
if (is_binary(string())) out += aux::to_hex(string());
else out += string();
out += print_string(string());
out += "'";
} break;
case list_t:
{
out += single_line ? "[ " : "[\n";
bool first = true;
for (list_type::const_iterator i = list().begin(); i != list().end(); ++i)
for (auto const& item : list())
{
if (!first) out += single_line ? ", " : ",\n";
first = false;
if (!single_line) add_indent(out, indent+1);
i->to_string_impl(out, indent+1, single_line);
item.to_string_impl(out, indent+1, single_line);
}
out += " ]";
} break;
@ -718,17 +723,16 @@ namespace {
{
out += single_line ? "{ " : "{\n";
bool first = true;
for (dictionary_type::const_iterator i = dict().begin(); i != dict().end(); ++i)
for (auto const& item : dict())
{
if (!first) out += single_line ? ", " : ",\n";
first = false;
if (!single_line) add_indent(out, indent+1);
out += "'";
if (is_binary(i->first)) out += aux::to_hex(i->first);
else out += i->first;
out += print_string(item.first);
out += "': ";
i->second.to_string_impl(out, indent+2, single_line);
item.second.to_string_impl(out, indent+2, single_line);
}
out += " }";
} break;
@ -737,6 +741,10 @@ namespace {
break;
case undefined_t:
out += "<uninitialized>";
break;
default:
out += "<error>";
break;
}
}
}