diff mbox

[1/2] utils.c: fix sizes in B & malloc in pretty_sizes

Message ID 1341854974-14502-1-git-send-email-pierre@spotify.com (mailing list archive)
State New, archived
Headers show

Commit Message

Pierre Carrier July 9, 2012, 5:29 p.m. UTC
Before, sizes below 1KB are still displayed in KB,
but without a unit.

Signed-off-by: Pierre Carrier <pierre@spotify.com>

Comments

David Sterba July 17, 2012, 12:43 p.m. UTC | #1
On Mon, Jul 09, 2012 at 05:29:34PM +0000, Pierre Carrier wrote:
> Before, sizes below 1KB are still displayed in KB,
> but without a unit.

Does it matter when the only size below 1KB one can get is 0 ? Though
for sake of consistency the B unit could be there in that case as well.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/utils.c b/utils.c
index aade9e2..937e763 100644
--- a/utils.c
+++ b/utils.c
@@ -1108,13 +1108,20 @@  char *pretty_sizes(u64 size)
 		size /= 1024;
 		num_divs++;
 	}
-	if (num_divs == 0)
+	if (num_divs <= 1) {
 		num_divs = 1;
+		fraction = (float)fract_size;
+	} else
+		fraction = (float)fract_size / 1024;
+
 	if (num_divs > ARRAY_SIZE(size_strs))
 		return NULL;
 
-	fraction = (float)fract_size / 1024;
+
 	pretty = malloc(pretty_len);
+	if (!pretty)
+		return NULL;
+
 	snprintf(pretty, pretty_len, "%.2f%s", fraction, size_strs[num_divs-1]);
 	return pretty;
 }