]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
lib: print_color_rate(): Fix formatting small rates in IEC mode
authorPetr Machata <me@pmachata.org>
Sat, 5 Dec 2020 21:13:33 +0000 (22:13 +0100)
committerDavid Ahern <dsahern@gmail.com>
Wed, 9 Dec 2020 02:30:41 +0000 (02:30 +0000)
ISO/IEC units are distinguished from the decadic ones by using a prefixes
like "Ki", "Mi" instead of "K" and "M". The current code inserts the letter
"i" after the decadic unit when in IEC mode. However it does so even when
the prefix is an empty string, formatting 1Kbit in IEC mode as "1000ibit".
Fix by omitting the letter if there is no prefix.

Signed-off-by: Petr Machata <me@pmachata.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
lib/json_print.c

index d28e957c96033a8f100c03ce1924e7e162ada841..b086123ad1f48a758730a45aaa4c38f9593b0df9 100644 (file)
@@ -333,7 +333,8 @@ int print_color_rate(bool use_iec, enum output_type type, enum color_attr color,
                rate /= kilo;
        }
 
-       rc = asprintf(&buf, "%.0f%s%sbit", (double)rate, units[i], str);
+       rc = asprintf(&buf, "%.0f%s%sbit", (double)rate, units[i],
+                     i > 0 ? str : "");
        if (rc < 0)
                return -1;