From 6603b51576a5e6c597c0588566c8b66b5a7d1afd Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Sat, 27 Jan 2007 16:35:56 +0000 Subject: [PATCH] Due to recent issues... assert() seed counts --- trackerlogic.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/trackerlogic.c b/trackerlogic.c index 6b8dba5..dfff041 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -14,6 +14,7 @@ #include #include +#include #include #include "scan.h" #include "byte.h" @@ -205,11 +206,17 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) { memmove( peer_dest, peer, sizeof( ot_peer ) ); if( OT_FLAG(peer) & PEER_FLAG_SEEDING ) torrent->peer_list->seed_count[0]++; + + assert( torrent->peer_list->seed_count[0] <= torrent->peer_list->peers[0].size ); + for( i=1; ipeer_list->peers[i], peer ) ) { case 0: continue; case 2: torrent->peer_list->seed_count[i]--; - case 1: default: return torrent; + case 1: default: + assert( torrent->peer_list->seed_count[i] > 0 ); + assert( torrent->peer_list->seed_count[i] <= torrent->peer_list->peers[i].size ); + return torrent; } } } else { @@ -217,6 +224,9 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) { torrent->peer_list->seed_count[0]--; if( !(OT_FLAG(peer_dest) & PEER_FLAG_SEEDING ) && (OT_FLAG(peer) & PEER_FLAG_SEEDING ) ) torrent->peer_list->seed_count[0]++; + + assert( torrent->peer_list->seed_count[0] > 0 ); + assert( torrent->peer_list->seed_count[0] <= torrent->peer_list->peers[0].size ); } return torrent; @@ -452,7 +462,10 @@ void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) { switch( vector_remove_peer( &torrent->peer_list->peers[i], peer ) ) { case 0: continue; case 2: torrent->peer_list->seed_count[i]--; - case 1: default: return; + case 1: default: + assert( torrent->peer_list->seed_count[i] > 0 ); + assert( torrent->peer_list->seed_count[i] <= torrent->peer_list->peers[i].size ); + return; } }