From 6d5e48f9e242a332a8509b580fa91ff5e9cbdfe2 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Tue, 9 May 2017 14:20:26 +0300 Subject: [PATCH] Fix some more off-by-one errors on last piece See: TRAC-4037 and e2584b04ff --- libtransmission/resume.c | 4 ++-- libtransmission/torrent.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libtransmission/resume.c b/libtransmission/resume.c index 1af499a0c..d63c52b4e 100644 --- a/libtransmission/resume.c +++ b/libtransmission/resume.c @@ -483,7 +483,7 @@ static void saveProgress(tr_variant* dict, tr_torrent* tor) tr_file const* f = &inf->files[fi]; /* get the oldest and newest nonzero timestamps for pieces in this file */ - for (p = &inf->pieces[f->firstPiece], pend = &inf->pieces[f->lastPiece]; p != pend; ++p) + for (p = &inf->pieces[f->firstPiece], pend = &inf->pieces[f->lastPiece] + 1; p != pend; ++p) { if (p->timeChecked == 0) { @@ -627,7 +627,7 @@ static uint64_t loadProgress(tr_variant* dict, tr_torrent* tor) { tr_file const* f = &inf->files[fi]; tr_piece* p = &inf->pieces[f->firstPiece]; - tr_piece const* pend = &inf->pieces[f->lastPiece]; + tr_piece const* pend = &inf->pieces[f->lastPiece] + 1; time_t const mtime = tr_torrentGetFileMTime(tor, fi); time_t const timeChecked = mtime == t ? mtime : 0; diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index fe819d83b..5c80a47cb 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -3456,7 +3456,7 @@ static void tr_torrentFileCompleted(tr_torrent* tor, tr_file_index_t fileIndex) /* now that the file is complete and closed, we can start watching its * mtime timestamp for changes to know if we need to reverify pieces */ - for (p = &inf->pieces[f->firstPiece], pend = &inf->pieces[f->lastPiece]; p != pend; ++p) + for (p = &inf->pieces[f->firstPiece], pend = &inf->pieces[f->lastPiece] + 1; p != pend; ++p) { p->timeChecked = now; }