From: Scott Baker Date: Mon, 7 Jun 2021 16:31:38 +0000 (-0700) Subject: Some fixes to address things @felixhandte found X-Git-Tag: v1.5.1~1^2~149^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1eb852854b48f7258b74d4e781e036db1b260607;p=thirdparty%2Fzstd.git Some fixes to address things @felixhandte found --- diff --git a/programs/util.c b/programs/util.c index f99bf82c5..934ec526d 100644 --- a/programs/util.c +++ b/programs/util.c @@ -121,8 +121,14 @@ int UTIL_requireUserConfirmation(const char* prompt, const char* abortMsg, * Functions ***************************************/ +/* + * Take a size in bytes and output a human readable string. Maximum + * buffer size is 8 but it's usually 7. Example: "123.4G" +*/ char* humanSize(unsigned long long size, char* str) { - if (size > 1125899906842624L) { + if (size > 1152921504606846976L) { + snprintf(str, 7, "%.1fE", (float)size / 1152921504606846976L); + } else if (size > 1125899906842624L) { snprintf(str, 7, "%.1fP", (float)size / 1125899906842624L); } else if (size > 1099511627776L) { snprintf(str, 7, "%.1fT", (float)size / 1099511627776L); @@ -134,8 +140,6 @@ char* humanSize(unsigned long long size, char* str) { snprintf(str, 7, "%.1fK", (float)size / 1024); } else if (size <= 1024) { snprintf(str, 7, "%lluB", size); - } else { - str[0] = '\0'; } return str; diff --git a/programs/util.h b/programs/util.h index 0eb64c013..ba2ae13c8 100644 --- a/programs/util.h +++ b/programs/util.h @@ -122,6 +122,10 @@ int UTIL_requireUserConfirmation(const char* prompt, const char* abortMsg, const #define STRDUP(s) strdup(s) #endif +/* + * Take a size in bytes and output a human readable string. Maximum + * buffer size is 8 but it's usually 7. Example: "123.4G" +*/ char* humanSize(unsigned long long size, char* str); /**