forked from enlightenment/terminology
tyls: rewrite size_print to avoid arithmetic exception
This commit is contained in:
parent
6c2e2dfbf5
commit
4d7708a0f1
|
@ -44,20 +44,20 @@ echo_on(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
size_print(char *buf, int bufsz, char *sz, unsigned long long size)
|
size_print(char *buf, int bufsz, char *sz, long long size)
|
||||||
{
|
{
|
||||||
char prefixes[] = " KMGTPEZY";
|
char *prefix = " KMGTPEZY";
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
while (prefixes[i])
|
while (*prefix)
|
||||||
{
|
{
|
||||||
if (size < (1024ULL << 10 * i) || !prefixes[i])
|
if ((size < 1024) || (*prefix == 'Y'))
|
||||||
{
|
{
|
||||||
snprintf(buf, bufsz, "%4lld", size / (1024 << 10 * (i - 1)));
|
snprintf(buf, bufsz, "%4lld", size);
|
||||||
*sz = prefixes[i];
|
*sz = *prefix;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
++i;
|
size >>= 10;
|
||||||
|
prefix++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue