(trunk libT) more runtime safety checks

This commit is contained in:
Charles Kerr 2008-12-16 23:31:05 +00:00
parent 69b8caa93b
commit 1a7ab297ea
1 changed files with 20 additions and 7 deletions

View File

@ -1336,6 +1336,12 @@ tr_peerMgrAddIncoming( tr_peerMgr * manager,
managerUnlock( manager );
}
static int
tr_isPex( const tr_pex * pex )
{
return pex && tr_isAddress( &pex->addr );
}
void
tr_peerMgrAddPex( tr_peerMgr * manager,
const uint8_t * torrentHash,
@ -1343,9 +1349,10 @@ tr_peerMgrAddPex( tr_peerMgr * manager,
const tr_pex * pex )
{
Torrent * t;
managerLock( manager );
assert( tr_isPex( pex ) );
t = getExistingTorrent( manager, torrentHash );
if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->addr ) )
ensureAtomExists( t, &pex->addr, pex->port, pex->flags, from );
@ -1463,11 +1470,17 @@ tr_pexCompare( const void * va, const void * vb )
{
const tr_pex * a = va;
const tr_pex * b = vb;
int i = tr_compareAddresses( &a->addr, &b->addr );
int i;
assert( tr_isPex( a ) );
assert( tr_isPex( b ) );
if(( i = tr_compareAddresses( &a->addr, &b->addr )))
return i;
if( a->port != b->port )
return a->port < b->port ? -1 : 1;
if( i ) return i;
if( a->port < b->port ) return -1;
if( a->port > b->port ) return 1;
return 0;
}
@ -1529,14 +1542,14 @@ tr_peerMgrGetPeers( tr_peerMgr * manager,
}
}
#warning this for loop can be removed when we're sure the bug is fixed
#warning this for loop can be removed when we are sure the bug is fixed
for( i=0; i<peersReturning; ++i )
assert( tr_isAddress( &pex[i].addr ) );
assert( ( walk - pex ) == peersReturning );
qsort( pex, peersReturning, sizeof( tr_pex ), tr_pexCompare );
#warning this for loop can be removed when we're sure the bug is fixed
#warning this for loop can be removed when we are sure the bug is fixed
for( i=0; i<peersReturning; ++i )
assert( tr_isAddress( &pex[i].addr ) );