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

(2.0x libT) #3449 "overflow error in tr_truncd()" -- fixed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0x/libtransmission/utils-test.c

    r10965 r11050  
    354354}
    355355
     356static int
     357test_truncd( void )
     358{
     359    char buf[32];
     360
     361    tr_snprintf( buf, sizeof( buf ), "%.2f%%", 99.999 );
     362    check( !strcmp( buf, "100.00%" ) );
     363
     364    tr_snprintf( buf, sizeof( buf ), "%.2f%%", tr_truncd( 99.999, 2 ) );
     365    check( !strcmp( buf, "99.99%" ) );
     366
     367    tr_snprintf( buf, sizeof( buf ), "%.4f", tr_truncd( 403650.656250, 4 ) );
     368    check( !strcmp( buf, "403650.6562" ) );
     369
     370    return 0;
     371}
     372
    356373int
    357374main( void )
    358375{
    359     char buf[32];
    360376    char *in, *out;
    361377    int   len;
    362378    int   i;
    363379    int   l;
    364 
    365     /* tr_truncd */
    366     tr_snprintf( buf, sizeof( buf ), "%.2f%%", 99.999 );
    367     check( !strcmp( buf, "100.00%" ) );
    368     tr_snprintf( buf, sizeof( buf ), "%.2f%%", tr_truncd( 99.999, 2 ) );
    369     check( !strcmp( buf, "99.99%" ) );
    370380
    371381    /* base64 */
     
    402412    if( ( i = test_url( ) ) )
    403413        return i;
     414    if( ( i = test_truncd( ) ) )
     415        return i;
    404416
    405417    /* test that tr_cryptoRandInt() stays in-bounds */
Note: See TracChangeset for help on using the changeset viewer.