From 4bf613804c5cff769e0228b0bd46afdde3bd96d6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 21 Feb 2022 14:20:35 -0600 Subject: [PATCH 1/2] fix: bitfield assertion failure on zero-byte file Fixes #2667. --- libtransmission/torrent.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index 3c29ef7d8..61065dc9d 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -2002,9 +2002,9 @@ tr_block_span_t tr_torGetFileBlockSpan(tr_torrent const* tor, tr_file_index_t i) auto const [begin_byte, end_byte] = tor->fpm_.byteSpan(i); auto const begin_block = tor->byteLoc(begin_byte).block; - if (begin_byte >= end_byte) + if (begin_byte >= end_byte) // 0-byte file { - return { begin_block, begin_block }; + return { begin_block, begin_block + 1}; } auto const final_block = tor->byteLoc(end_byte - 1).block; From 81441706c188f6d8c33739920818ce620abe90d7 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 21 Feb 2022 14:39:00 -0600 Subject: [PATCH 2/2] fixup! fix: bitfield assertion failure on zero-byte file chore: code style --- libtransmission/torrent.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index 61065dc9d..ff70169b8 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -2004,7 +2004,7 @@ tr_block_span_t tr_torGetFileBlockSpan(tr_torrent const* tor, tr_file_index_t i) auto const begin_block = tor->byteLoc(begin_byte).block; if (begin_byte >= end_byte) // 0-byte file { - return { begin_block, begin_block + 1}; + return { begin_block, begin_block + 1 }; } auto const final_block = tor->byteLoc(end_byte - 1).block;