[sheepdog] [PATCH] collie: fill line with spaces correctly in show_progress()

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu May 16 16:11:36 CEST 2013


The current collie doesn't print spaces after the progress bar to the
end of line, so the error message aren't be formated correctly.

For example:

  $ collie vdi check test
   98.0 % [============================>] 196 MB / 200 MB   f
  ixed missing 7c2b2500000011
  100.0 % [=============================] 200 MB / 200 MB
  finish check&repair test

This fixes the problem.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/vdi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/collie/vdi.c b/collie/vdi.c
index 3520e2f..27a8418 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -117,7 +117,7 @@ static void show_progress(uint64_t done, uint64_t total)
 	size_to_str(done, done_str, sizeof(done_str));
 	size_to_str(total, total_str, sizeof(total_str));
 
-	buf = xmalloc(screen_width);
+	buf = xmalloc(screen_width + 1);
 	snprintf(buf, screen_width, "%5.1lf %% [", (double)done / total * 100);
 
 	for (int i = 0; i < bar_length; i++) {
@@ -133,8 +133,8 @@ static void show_progress(uint64_t done, uint64_t total)
 		 "] %s / %s", done_str, total_str);
 
 	/* fill the rest of buffer with blank characters */
-	memset(buf + strlen(buf), ' ', screen_width - strlen(buf) - 1);
-	buf[screen_width - 1] = '\0';
+	memset(buf + strlen(buf), ' ', screen_width - strlen(buf));
+	buf[screen_width] = '\0';
 	printf("%s", buf);
 
 	if (done == total)
-- 
1.8.1.3.566.gaa39828




More information about the sheepdog mailing list