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

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

View File

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

View File

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