tyls: rewrite size_print to avoid arithmetic exception

This commit is contained in:
Boris Faure 2015-02-26 23:46:58 +01:00
parent 6c2e2dfbf5
commit 4d7708a0f1
1 changed files with 8 additions and 8 deletions

View File

@ -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++;
} }
} }