diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index ffe7aaa29..4dc821d7d 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -564,9 +564,11 @@ namespace libtorrent for (int j = 0; j < num_bitmask_bytes; ++j) { unsigned char v = 0; - for (int k = 0; k < 8; ++k) + int bits = std::min(num_blocks_per_piece - j*8, 8); + for (int k = 0; k < bits; ++k) v |= i->info[j*8+k].finished?(1 << k):0; bitmask.insert(bitmask.end(), v); + assert(bits == 8 || j == num_bitmask_bytes - 1); } piece_struct["bitmask"] = bitmask;