From 63bad25bbfd6851eface06e3d1d7acbfa3e28929 Mon Sep 17 00:00:00 2001 From: kevans Date: Wed, 3 Oct 2018 17:20:30 +0000 Subject: [PATCH] MFC r338646: dd(1): Correct padding in status=progress Output padding is specified via outlen, which is set using the return value of fprintf. Because it's printing that padding plus a trailing byte, it grows by one each iteration rather than reflecting actual length. Additionally, iec was sized improperly for scaling up similarly to si. Fixing this revealed that the humanize_number(3) call to populate persec was using the wrong width. --- bin/dd/misc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/dd/misc.c b/bin/dd/misc.c index ea4fcc2955b..45c13c01a0e 100644 --- a/bin/dd/misc.c +++ b/bin/dd/misc.c @@ -109,7 +109,7 @@ progress(void) { static int outlen; char si[4 + 1 + 2 + 1]; /* 123 NUL */ - char iec[4 + 1 + 2 + 1]; /* 123 NUL */ + char iec[4 + 1 + 3 + 1]; /* 123 NUL */ char persec[4 + 1 + 2 + 1]; /* 123 NUL */ char *buf; double secs; @@ -119,11 +119,11 @@ progress(void) HN_DECIMAL | HN_DIVISOR_1000); humanize_number(iec, sizeof(iec), (int64_t)st.bytes, "B", HN_AUTOSCALE, HN_DECIMAL | HN_IEC_PREFIXES); - humanize_number(persec, sizeof(iec), (int64_t)(st.bytes / secs), "B", + humanize_number(persec, sizeof(persec), (int64_t)(st.bytes / secs), "B", HN_AUTOSCALE, HN_DECIMAL | HN_DIVISOR_1000); asprintf(&buf, " %'ju bytes (%s, %s) transferred %.3fs, %s/s", (uintmax_t)st.bytes, si, iec, secs, persec); - outlen = fprintf(stderr, "%-*s\r", outlen, buf); + outlen = fprintf(stderr, "%-*s\r", outlen, buf) - 1; fflush(stderr); free(buf); need_progress = 0; -- 2.45.0