mirror of
https://github.com/transmission/transmission.git
synced 2025-12-19 18:08:31 +00:00
refactor: remove last byte special case in tr_block_info::byte_loc() (#7064)
* refactor: remove last byte special case in `tr_block_info::byte_loc()` * fix: handle 0-byte file at the end of torrent in fpm * test: modify test for 0-byte file at the end of torrent * fix: handle 0-byte file at the end of torrent in `block_span_for_file`
This commit is contained in:
@@ -83,16 +83,8 @@ public:
|
||||
{
|
||||
loc.byte = byte_idx;
|
||||
|
||||
if (byte_idx == total_size()) // handle 0-byte files at the end of a torrent
|
||||
{
|
||||
loc.block = block_count() - 1U;
|
||||
loc.piece = piece_count() - 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
loc.block = static_cast<tr_block_index_t>(byte_idx / BlockSize);
|
||||
loc.piece = static_cast<tr_piece_index_t>(byte_idx / piece_size());
|
||||
}
|
||||
loc.block = static_cast<tr_block_index_t>(byte_idx / BlockSize);
|
||||
loc.piece = static_cast<tr_piece_index_t>(byte_idx / piece_size());
|
||||
|
||||
loc.block_offset = static_cast<uint32_t>(loc.byte - (uint64_t{ loc.block } * BlockSize));
|
||||
loc.piece_offset = static_cast<uint32_t>(loc.byte - (uint64_t{ loc.piece } * piece_size()));
|
||||
|
||||
Reference in New Issue
Block a user