From a67640bddb8af2645449d92c50ad8695f1cd346d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 20 Jan 2013 19:35:47 +0000 Subject: [PATCH] merged fix from RC_0_16 --- include/libtorrent/peer_id.hpp | 2 ++ test/test_primitives.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/libtorrent/peer_id.hpp b/include/libtorrent/peer_id.hpp index 5d57cc3aa..18d19a9ef 100644 --- a/include/libtorrent/peer_id.hpp +++ b/include/libtorrent/peer_id.hpp @@ -134,6 +134,7 @@ namespace libtorrent m_number[i] <<= n; m_number[i] |= m_number[i+1] >> (8 - n); } + m_number[number_size-1] <<= n; } return *this; } @@ -160,6 +161,7 @@ namespace libtorrent m_number[i] >>= n; m_number[i] |= m_number[i-1] << (8 - n); } + m_number[0] >>= n; } return *this; } diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index 2466f8293..72d0985ee 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -1835,6 +1835,34 @@ int test_main() std::cerr << h1 << std::endl; #endif TEST_CHECK(h1 == to_hash("000fffffff0000000000ffffffffff0000000000")); + + h1 = to_hash("7000000000000000000000000000000000000000"); + h1 <<= 1; +#if TORRENT_USE_IOSTREAM + std::cerr << h1 << std::endl; +#endif + TEST_CHECK(h1 == to_hash("e000000000000000000000000000000000000000")); + + h1 = to_hash("0000000000000000000000000000000000000007"); + h1 <<= 1; +#if TORRENT_USE_IOSTREAM + std::cerr << h1 << std::endl; +#endif + TEST_CHECK(h1 == to_hash("000000000000000000000000000000000000000e")); + + h1 = to_hash("0000000000000000000000000000000000000007"); + h1 >>= 1; +#if TORRENT_USE_IOSTREAM + std::cerr << h1 << std::endl; +#endif + TEST_CHECK(h1 == to_hash("0000000000000000000000000000000000000003")); + + h1 = to_hash("7000000000000000000000000000000000000000"); + h1 >>= 1; +#if TORRENT_USE_IOSTREAM + std::cerr << h1 << std::endl; +#endif + TEST_CHECK(h1 == to_hash("3800000000000000000000000000000000000000")); // CIDR distance test h1 = to_hash("0123456789abcdef01232456789abcdef0123456");