mirror of
https://github.com/transmission/transmission
synced 2024-12-25 09:13:06 +00:00
(trunk libT) more runtime safety checks
This commit is contained in:
parent
69b8caa93b
commit
1a7ab297ea
1 changed files with 20 additions and 7 deletions
|
@ -1336,6 +1336,12 @@ tr_peerMgrAddIncoming( tr_peerMgr * manager,
|
||||||
managerUnlock( manager );
|
managerUnlock( manager );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
tr_isPex( const tr_pex * pex )
|
||||||
|
{
|
||||||
|
return pex && tr_isAddress( &pex->addr );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tr_peerMgrAddPex( tr_peerMgr * manager,
|
tr_peerMgrAddPex( tr_peerMgr * manager,
|
||||||
const uint8_t * torrentHash,
|
const uint8_t * torrentHash,
|
||||||
|
@ -1343,9 +1349,10 @@ tr_peerMgrAddPex( tr_peerMgr * manager,
|
||||||
const tr_pex * pex )
|
const tr_pex * pex )
|
||||||
{
|
{
|
||||||
Torrent * t;
|
Torrent * t;
|
||||||
|
|
||||||
managerLock( manager );
|
managerLock( manager );
|
||||||
|
|
||||||
|
assert( tr_isPex( pex ) );
|
||||||
|
|
||||||
t = getExistingTorrent( manager, torrentHash );
|
t = getExistingTorrent( manager, torrentHash );
|
||||||
if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->addr ) )
|
if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->addr ) )
|
||||||
ensureAtomExists( t, &pex->addr, pex->port, pex->flags, from );
|
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 * a = va;
|
||||||
const tr_pex * b = vb;
|
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;
|
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 )
|
for( i=0; i<peersReturning; ++i )
|
||||||
assert( tr_isAddress( &pex[i].addr ) );
|
assert( tr_isAddress( &pex[i].addr ) );
|
||||||
|
|
||||||
assert( ( walk - pex ) == peersReturning );
|
assert( ( walk - pex ) == peersReturning );
|
||||||
qsort( pex, peersReturning, sizeof( tr_pex ), tr_pexCompare );
|
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 )
|
for( i=0; i<peersReturning; ++i )
|
||||||
assert( tr_isAddress( &pex[i].addr ) );
|
assert( tr_isAddress( &pex[i].addr ) );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue