Fix rate display width when it is exactly 0 in bytes mode.

This commit is contained in:
Andrew Wood
2023-07-23 22:29:09 +01:00
parent d4590e1f3b
commit e0856df8ef
+12 -2
View File
@@ -183,9 +183,17 @@ static void pv__si_prefix(long double *value, char *prefix,
/*
* Force an empty prefix if the value is zero to avoid "0yB".
*
* See below's "is_bytes" check for the reason we add another space
* in bytes mode.
*/
if (0.0 == *value)
if (0.0 == *value) {
if (is_bytes) {
prefix[1] = ' ';
prefix[2] = 0;
}
return;
}
cutoff = ratio * 0.97;
@@ -227,11 +235,13 @@ static void pv__sizestr(char *buffer, int bufsize, char *format,
char *suffix_bytes, int is_bytes)
{
char sizestr_buffer[256];
char si_prefix[8] = " ";
char si_prefix[8];
long double divider;
long double display_amount;
char *suffix;
(void) pv_snprintf(si_prefix, sizeof(si_prefix), "%s", " ");
if (is_bytes) {
suffix = suffix_bytes;
divider = 1024.0;