Changeset 11049


Ignore:
Timestamp:
Jul 24, 2010, 5:09:39 PM (12 years ago)
Author:
charles
Message:

(trunk libT) #3449 "overflow error in tr_truncd()" -- fixed.

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils-test.c

    r10966 r11049  
    376376}
    377377
     378static int
     379test_truncd( void )
     380{
     381    char buf[32];
     382
     383    tr_snprintf( buf, sizeof( buf ), "%.2f%%", 99.999 );
     384    check( !strcmp( buf, "100.00%" ) );
     385
     386    tr_snprintf( buf, sizeof( buf ), "%.2f%%", tr_truncd( 99.999, 2 ) );
     387    check( !strcmp( buf, "99.99%" ) );
     388
     389    tr_snprintf( buf, sizeof( buf ), "%.4f", tr_truncd( 403650.656250, 4 ) );
     390    check( !strcmp( buf, "403650.6562" ) );
     391
     392    return 0;
     393}
     394
    378395int
    379396main( void )
    380397{
    381     char buf[32];
    382398    char *in, *out;
    383399    int   len;
    384400    int   i;
    385401    int   l;
    386 
    387     /* tr_truncd */
    388     tr_snprintf( buf, sizeof( buf ), "%.2f%%", 99.999 );
    389     check( !strcmp( buf, "100.00%" ) );
    390     tr_snprintf( buf, sizeof( buf ), "%.2f%%", tr_truncd( 99.999, 2 ) );
    391     check( !strcmp( buf, "99.99%" ) );
    392402
    393403    /* base64 */
     
    426436    if( ( i = test_url( ) ) )
    427437        return i;
     438    if( ( i = test_truncd( ) ) )
     439        return i;
    428440
    429441    /* test that tr_cryptoRandInt() stays in-bounds */
  • trunk/libtransmission/utils.c

    r11015 r11049  
    13871387{
    13881388    const int i = (int) pow( 10, decimal_places ); 
    1389     double x2 = (int)(x*i);
     1389    const double x2 = (int64_t)(x * i);
    13901390    return x2 / i;
    13911391}
Note: See TracChangeset for help on using the changeset viewer.