mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
(trunk libT) #3449 "overflow error in tr_truncd()" -- fixed.
This commit is contained in:
@@ -375,21 +375,31 @@ test_url( void )
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
test_truncd( void )
|
||||
{
|
||||
char buf[32];
|
||||
|
||||
tr_snprintf( buf, sizeof( buf ), "%.2f%%", 99.999 );
|
||||
check( !strcmp( buf, "100.00%" ) );
|
||||
|
||||
tr_snprintf( buf, sizeof( buf ), "%.2f%%", tr_truncd( 99.999, 2 ) );
|
||||
check( !strcmp( buf, "99.99%" ) );
|
||||
|
||||
tr_snprintf( buf, sizeof( buf ), "%.4f", tr_truncd( 403650.656250, 4 ) );
|
||||
check( !strcmp( buf, "403650.6562" ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main( void )
|
||||
{
|
||||
char buf[32];
|
||||
char *in, *out;
|
||||
int len;
|
||||
int i;
|
||||
int l;
|
||||
|
||||
/* tr_truncd */
|
||||
tr_snprintf( buf, sizeof( buf ), "%.2f%%", 99.999 );
|
||||
check( !strcmp( buf, "100.00%" ) );
|
||||
tr_snprintf( buf, sizeof( buf ), "%.2f%%", tr_truncd( 99.999, 2 ) );
|
||||
check( !strcmp( buf, "99.99%" ) );
|
||||
|
||||
/* base64 */
|
||||
out = tr_base64_encode( "YOYO!", -1, &len );
|
||||
check( out );
|
||||
@@ -425,6 +435,8 @@ main( void )
|
||||
return i;
|
||||
if( ( i = test_url( ) ) )
|
||||
return i;
|
||||
if( ( i = test_truncd( ) ) )
|
||||
return i;
|
||||
|
||||
/* test that tr_cryptoRandInt() stays in-bounds */
|
||||
for( i = 0; i < 100000; ++i )
|
||||
|
||||
@@ -1386,7 +1386,7 @@ double
|
||||
tr_truncd( double x, int decimal_places )
|
||||
{
|
||||
const int i = (int) pow( 10, decimal_places );
|
||||
double x2 = (int)(x*i);
|
||||
const double x2 = (int64_t)(x * i);
|
||||
return x2 / i;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user