Author: kevans
Date: Thu Sep 13 14:54:46 2018
New Revision: 338646
URL: https://svnweb.freebsd.org/changeset/base/338646

Log:
  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.
  
  Submitted by: Thomas Hurst <t...@hur.st>
  Reviewed by:  imp
  Approved by:  re (kib)
  Differential Revision:        https://reviews.freebsd.org/D16960

Modified:
  head/bin/dd/misc.c

Modified: head/bin/dd/misc.c
==============================================================================
--- head/bin/dd/misc.c  Thu Sep 13 14:53:51 2018        (r338645)
+++ head/bin/dd/misc.c  Thu Sep 13 14:54:46 2018        (r338646)
@@ -111,7 +111,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;
@@ -121,11 +121,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;
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to