Fix integer overflow in the file size output when dealing with

large files (i.e. DVD images).

Reviewed by:  des@
This commit is contained in:
Lukas Ertl 2004-05-19 11:07:30 +00:00
parent a12d0a1aee
commit be28a6af38

View File

@ -148,7 +148,7 @@ stat_eta(struct xferstat *xs)
*/ */
static const char *prefixes = " kMGTP"; static const char *prefixes = " kMGTP";
static const char * static const char *
stat_bytes(size_t bytes) stat_bytes(off_t bytes)
{ {
static char str[16]; static char str[16];
const char *prefix = prefixes; const char *prefix = prefixes;
@ -157,7 +157,7 @@ stat_bytes(size_t bytes)
bytes /= 1024; bytes /= 1024;
prefix++; prefix++;
} }
snprintf(str, sizeof str, "%4zu %cB", bytes, *prefix); snprintf(str, sizeof str, "%4jd %cB", (intmax_t)bytes, *prefix);
return (str); return (str);
} }
@ -176,7 +176,7 @@ stat_bps(struct xferstat *xs)
snprintf(str, sizeof str, "?? Bps"); snprintf(str, sizeof str, "?? Bps");
} else { } else {
bps = (xs->rcvd - xs->offset) / delta; bps = (xs->rcvd - xs->offset) / delta;
snprintf(str, sizeof str, "%sps", stat_bytes((size_t)bps)); snprintf(str, sizeof str, "%sps", stat_bytes((off_t)bps));
} }
return (str); return (str);
} }