1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 16:52:39 +00:00

a better fix for the tr_rand() crash experienced earlier today

This commit is contained in:
Charles Kerr 2007-07-26 03:57:45 +00:00
parent a4af933874
commit 31ac4e604a
2 changed files with 4 additions and 1 deletions

View file

@ -685,7 +685,7 @@ writeEnd:
all peers for 2, and so on. Randomize our starting point
into "pool" to reduce such overlap */
int piecesLeft = poolSize;
int p = (int)(tr_date() % poolSize);
int p = piecesLeft ? tr_rand(piecesLeft) : 0;
for( ; openSlots>0 && piecesLeft>0; --piecesLeft, p=(p+1)%poolSize )
{
const int piece = pool[p];

View file

@ -168,6 +168,9 @@ void tr_msg( int level, char * msg, ... )
int tr_rand( int sup )
{
static int init = 0;
assert( sup > 0 );
if( !init )
{
srand( tr_date() );