Thread (9 messages) 9 messages, 2 authors, 2012-07-17
STALE5103d
Revisions (2)
  1. v1 [diff vs current]
  2. v1 current

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

From: Pierre Carrier <hidden>
Date: 2012-07-09 17:29:56
Subsystem: the rest · Maintainer: Linus Torvalds

Before, sizes below 1KB are still displayed in KB,
but without a unit.

Signed-off-by: Pierre Carrier <redacted>
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;
 }
-- 
1.7.11.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help