Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Oct 2018 17:20:30 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r339163 - stable/11/bin/dd
Message-ID:  <201810031720.w93HKUS7010287@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Wed Oct  3 17:20:30 2018
New Revision: 339163
URL: https://svnweb.freebsd.org/changeset/base/339163

Log:
  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.

Modified:
  stable/11/bin/dd/misc.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/bin/dd/misc.c
==============================================================================
--- stable/11/bin/dd/misc.c	Wed Oct  3 17:19:04 2018	(r339162)
+++ stable/11/bin/dd/misc.c	Wed Oct  3 17:20:30 2018	(r339163)
@@ -109,7 +109,7 @@ progress(void)
 {
 	static int outlen;
 	char si[4 + 1 + 2 + 1];		/* 123 <space> <suffix> NUL */
-	char iec[4 + 1 + 2 + 1];	/* 123 <space> <suffix> NUL */
+	char iec[4 + 1 + 3 + 1];	/* 123 <space> <suffix> NUL */
 	char persec[4 + 1 + 2 + 1];	/* 123 <space> <suffix> 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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201810031720.w93HKUS7010287>