From 96313ab0957dbf24c6e9dc6e4da59584eb16b30e Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Mon, 13 Feb 2012 20:02:24 +0100 Subject: [PATCH] Make format_human_readable_size saner for size < 1000 --- test/test_util.c | 7 ++++--- util.c | 6 +----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/test/test_util.c b/test/test_util.c index 6668c8649..19c0afe0d 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Joel Rosdahl + * Copyright (C) 2010-2012 Joel Rosdahl * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free @@ -96,8 +96,9 @@ TEST(subst_env_in_string) TEST(format_human_readable_size) { - CHECK_STR_EQ_FREE2("0", format_human_readable_size(0)); - CHECK_STR_EQ_FREE2("1 B", format_human_readable_size(1)); + CHECK_STR_EQ_FREE2("0.0 kB", format_human_readable_size(0)); + CHECK_STR_EQ_FREE2("0.0 kB", format_human_readable_size(49)); + CHECK_STR_EQ_FREE2("0.1 kB", format_human_readable_size(50)); CHECK_STR_EQ_FREE2("42.0 kB", format_human_readable_size(42 * 1000)); CHECK_STR_EQ_FREE2("1.0 MB", format_human_readable_size(1000 * 1000)); CHECK_STR_EQ_FREE2("1.2 MB", format_human_readable_size(1234 * 1000)); diff --git a/util.c b/util.c index 9b4eaef80..ef2dbec0f 100644 --- a/util.c +++ b/util.c @@ -858,12 +858,8 @@ format_human_readable_size(uint64_t v) s = format("%.1f GB", v/((double)(1000*1000*1000))); } else if (v >= 1000*1000) { s = format("%.1f MB", v/((double)(1000*1000))); - } else if (v >= 1000) { - s = format("%.1f kB", v/((double)(1000))); - } else if (v > 0) { - s = format("%u B", (unsigned)v); } else { - s = x_strdup("0"); + s = format("%.1f kB", v/((double)(1000))); } return s; } -- 2.47.3