From 8cec51fc4728b5e76605d6a70fb4fb57a3457c24 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 24 Dec 2010 01:22:49 +0000 Subject: [PATCH] fixes to make valgrind happy --- include/libtorrent/bitfield.hpp | 6 +++--- include/libtorrent/peer_id.hpp | 13 +++---------- src/peer_connection.cpp | 10 ++++++++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index 44dc195e3..bd53086bb 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -43,11 +43,11 @@ namespace libtorrent struct TORRENT_EXPORT bitfield { bitfield(): m_bytes(0), m_size(0), m_own(false) {} - bitfield(int bits): m_bytes(0), m_size(0) + bitfield(int bits): m_bytes(0), m_size(0), m_own(false) { resize(bits); } - bitfield(int bits, bool val): m_bytes(0), m_size(0) + bitfield(int bits, bool val): m_bytes(0), m_size(0), m_own(false) { resize(bits, val); } - bitfield(char const* b, int bits): m_bytes(0), m_size(0) + bitfield(char const* b, int bits): m_bytes(0), m_size(0), m_own(false) { assign(b, bits); } bitfield(bitfield const& rhs): m_bytes(0), m_size(0), m_own(false) { assign(rhs.bytes(), rhs.size()); } diff --git a/include/libtorrent/peer_id.hpp b/include/libtorrent/peer_id.hpp index 2a1e86a1e..d4443709c 100644 --- a/include/libtorrent/peer_id.hpp +++ b/include/libtorrent/peer_id.hpp @@ -65,7 +65,7 @@ namespace libtorrent public: enum { size = number_size }; - big_number() {} + big_number() { clear(); } static big_number max() { @@ -101,15 +101,8 @@ namespace libtorrent std::memcpy(m_number, s.c_str(), sl); } - void assign(char const* str) - { - std::memcpy(m_number, str, size); - } - - void clear() - { - std::fill(m_number,m_number+number_size,(const unsigned char)(0)); - } + void assign(char const* str) { std::memcpy(m_number, str, size); } + void clear() { std::memset(m_number, 0, number_size); } bool is_all_zeros() const { diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 892ba1d13..d5f1db835 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -66,6 +66,11 @@ using libtorrent::aux::session_impl; namespace libtorrent { + int round_up8(int v) + { + return ((v & 7) == 0) ? v : v + (8 - (v & 7)); + } + // outbound connection peer_connection::peer_connection( session_impl& ses @@ -4630,7 +4635,7 @@ namespace libtorrent int regular_buffer_size = m_packet_size - m_disk_recv_buffer_size; if (int(m_recv_buffer.size()) < regular_buffer_size) - m_recv_buffer.resize(regular_buffer_size); + m_recv_buffer.resize(round_up8(regular_buffer_size)); boost::array vec; int num_bufs = 0; @@ -4938,7 +4943,8 @@ namespace libtorrent && m_recv_pos == 0 && (m_recv_buffer.capacity() - m_packet_size) > 128) { - buffer(m_packet_size).swap(m_recv_buffer); + // round up to an even 8 bytes since that's the RC4 blocksize + buffer(round_up8(m_packet_size)).swap(m_recv_buffer); } if (m_recv_pos >= m_soft_packet_size) m_soft_packet_size = 0;