Fix shortening of negative memory values.

This commit is contained in:
Bartosz Taudul 2018-08-09 02:25:47 +02:00
parent 4a12e14a1b
commit 92c1685528

View File

@ -182,7 +182,9 @@ static const char* MemSizeToString( int64_t val )
char* buf = bufpool[bufsel]; char* buf = bufpool[bufsel];
bufsel = ( bufsel + 1 ) % Pool; bufsel = ( bufsel + 1 ) % Pool;
if( val < 10000ll ) const auto aval = abs( val );
if( aval < 10000ll )
{ {
sprintf( buf, "%" PRIi64 " bytes", val ); sprintf( buf, "%" PRIi64 " bytes", val );
return buf; return buf;
@ -197,17 +199,17 @@ static const char* MemSizeToString( int64_t val )
}; };
Unit unit; Unit unit;
if( val < 10000ll * 1024 ) if( aval < 10000ll * 1024 )
{ {
sprintf( buf, "%.2f", val / 1024. ); sprintf( buf, "%.2f", val / 1024. );
unit = Unit::Kilobyte; unit = Unit::Kilobyte;
} }
else if( val < 10000ll * 1024 * 1024 ) else if( aval < 10000ll * 1024 * 1024 )
{ {
sprintf( buf, "%.2f", val / ( 1024. * 1024 ) ); sprintf( buf, "%.2f", val / ( 1024. * 1024 ) );
unit = Unit::Megabyte; unit = Unit::Megabyte;
} }
else if( val < 10000ll * 1024 * 1024 * 1024 ) else if( aval < 10000ll * 1024 * 1024 * 1024 )
{ {
sprintf( buf, "%.2f", val / ( 1024. * 1024 * 1024 ) ); sprintf( buf, "%.2f", val / ( 1024. * 1024 * 1024 ) );
unit = Unit::Gigabyte; unit = Unit::Gigabyte;