diff --git a/libtransmission/crypto.c b/libtransmission/crypto.c index 6257b74dc..1b85450ca 100644 --- a/libtransmission/crypto.c +++ b/libtransmission/crypto.c @@ -311,6 +311,8 @@ tr_cryptoRandInt( int upperBound ) int noise; int val; + assert( upperBound > 0 ); + if( RAND_pseudo_bytes ( (unsigned char *) &noise, sizeof noise ) >= 0 ) { val = abs( noise ) % upperBound; @@ -328,17 +330,22 @@ tr_cryptoRandInt( int upperBound ) int tr_cryptoWeakRandInt( int upperBound ) { - static int init = 0; + int val; + static tr_bool init = FALSE; assert( upperBound > 0 ); if( !init ) { srand( tr_date( ) ); - init = 1; + init = TRUE; } - return rand( ) % upperBound; + + val = rand( ) % upperBound; + assert( val >= 0 ); + assert( val < upperBound ); + return val; } void