Changeset 8438


Ignore:
Timestamp:
May 19, 2009, 8:52:24 PM (14 years ago)
Author:
charles
Message:

(trunk libT) add some extra tests to tr_cryptoWeakRandInt()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/crypto.c

    r8085 r8438  
    312312    int val;
    313313
     314    assert( upperBound > 0 );
     315
    314316    if( RAND_pseudo_bytes ( (unsigned char *) &noise, sizeof noise ) >= 0 )
    315317    {
     
    329331tr_cryptoWeakRandInt( int upperBound )
    330332{
    331     static int init = 0;
     333    int val;
     334    static tr_bool init = FALSE;
    332335
    333336    assert( upperBound > 0 );
     
    336339    {
    337340        srand( tr_date( ) );
    338         init = 1;
    339     }
    340 
    341     return rand( ) % upperBound;
     341        init = TRUE;
     342    }
     343
     344   
     345    val = rand( ) % upperBound;
     346    assert( val >= 0 );
     347    assert( val < upperBound );
     348    return val;
    342349}
    343350
Note: See TracChangeset for help on using the changeset viewer.