]> granicus.if.org Git - transmission/commitdiff
Fix some more off-by-one errors on last piece
authorMike Gelfand <mikedld@mikedld.com>
Tue, 9 May 2017 11:20:26 +0000 (14:20 +0300)
committerMike Gelfand <mikedld@mikedld.com>
Tue, 9 May 2017 11:23:25 +0000 (14:23 +0300)
See: TRAC-4037 and e2584b04ff

libtransmission/resume.c
libtransmission/torrent.c

index 1af499a0c8db1f2a3c9878b5f74d8df0da781215..d63c52b4e219350e150d348b5b437e018a479fdd 100644 (file)
@@ -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;
 
index fe819d83b51642ff43265a4d9d72882b3765e235..5c80a47cb423f5c906597140a61c55db65a615f0 100644 (file)
@@ -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;
     }