Fix formatBytecount's sizes (#1928)

This caused a crash (ref #1925) when seek was set to UT64_MAX.
This commit is contained in:
yossizap 2019-12-15 07:44:43 +00:00 committed by Itay Cohen
parent 59af77fb72
commit 64371bb07a
2 changed files with 7 additions and 5 deletions

View File

@ -23,16 +23,18 @@ static QAbstractItemView::ScrollMode scrollMode()
namespace qhelpers { namespace qhelpers {
QString formatBytecount(const long bytecount) QString formatBytecount(const uint64_t bytecount)
{ {
if (bytecount == 0) if (bytecount == 0) {
return "0"; return "0";
const int exp = log(bytecount) / log(1000); }
const int exp = log(bytecount) / log(1024);
constexpr char suffixes[] = {' ', 'k', 'M', 'G', 'T', 'P', 'E'}; constexpr char suffixes[] = {' ', 'k', 'M', 'G', 'T', 'P', 'E'};
QString str; QString str;
QTextStream stream(&str); QTextStream stream(&str);
stream << qSetRealNumberPrecision(3) << bytecount / pow(1000, exp) stream << qSetRealNumberPrecision(3) << bytecount / pow(1024, exp)
<< ' ' << suffixes[exp] << 'B'; << ' ' << suffixes[exp] << 'B';
return stream.readAll(); return stream.readAll();
} }

View File

@ -21,7 +21,7 @@ class QMenu;
class QPaintDevice; class QPaintDevice;
namespace qhelpers { namespace qhelpers {
QString formatBytecount(const long bytecount); QString formatBytecount(const uint64_t bytecount);
void adjustColumns(QTreeView *tv, int columnCount, int padding); void adjustColumns(QTreeView *tv, int columnCount, int padding);
void adjustColumns(QTreeWidget *tw, int padding); void adjustColumns(QTreeWidget *tw, int padding);
bool selectFirstItem(QAbstractItemView *itemView); bool selectFirstItem(QAbstractItemView *itemView);