summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--btpd/upload.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/btpd/upload.c b/btpd/upload.c
index 4ce7b42..5ae7f1b 100644
--- a/btpd/upload.c
+++ b/btpd/upload.c
@@ -62,12 +62,12 @@ choke_do(void)
         qsort(worthy, nworthy, sizeof(worthy[0]), rate_cmp);
 
         bzero(unchoked, sizeof(unchoked));
-        for (i = nworthy - 1; i >= 0 && found < m_max_downloaders - 1; i--) {
-            if ((worthy[i].p->flags & PF_P_WANT) != 0)
+        for (i = nworthy; i > 0 && found < m_max_downloaders - 1; i--) {
+            if ((worthy[i - 1].p->flags & PF_P_WANT) != 0)
                 found++;
-            if ((worthy[i].p->flags & PF_I_CHOKE) != 0)
+            if ((worthy[i - 1].p->flags & PF_I_CHOKE) != 0)
                 peer_unchoke(p);
-            unchoked[worthy[i].i] = 1;
+            unchoked[worthy[i - 1].i] = 1;
         }
 
         i = 0;