display_options: print_size: Fix order overflow
Function print_size() round size to the nearst value with one decimal
fraction number. But in special cases also unit order may overflow.
For example value 1073689396 is printed as "1024 MiB" and value 1073741824
as "1 GiB".
Fix this issue by detecting order overflow and increasing unit order.
With this change also value 1073689396 is printed as "1 GiB".
Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
diff --git a/test/lib/test_print.c b/test/lib/test_print.c
index a60a5a5..79b67c7 100644
--- a/test/lib/test_print.c
+++ b/test/lib/test_print.c
@@ -68,6 +68,9 @@
ut_assertok(test_print_size(uts, 7654321, "7.3 MiB;"));
ut_assertok(test_print_size(uts, 87654321, "83.6 MiB;"));
ut_assertok(test_print_size(uts, 987654321, "941.9 MiB;"));
+ ut_assertok(test_print_size(uts, 1073689395, "1023.9 MiB;"));
+ ut_assertok(test_print_size(uts, 1073689396, "1 GiB;"));
+ ut_assertok(test_print_size(uts, 1073741824, "1 GiB;"));
ut_assertok(test_print_size(uts, 1987654321, "1.9 GiB;"));
ut_assertok(test_print_size(uts, 54321987654321, "49.4 TiB;"));
return 0;