Module Name: othersrc
Committed By: agc
Date: Tue Sep 1 03:47:28 UTC 2015
Modified Files:
othersrc/external/bsd/progress/dist: progress.c
Log Message:
Update from [email protected] for the progress meter code, from FreeBSD r286965,
mucked around by me. This fixes a bug in the progress display code:
"When the user's filename is too big, or his terminal width is too
small, the progress code could wind up using a negative number for
the length of the "stars" that it uses to indicate progress.
This negative value was assigned to an unsigned variable, resulting
in a very large positive value.
The result is that we wound up writing garbage from memory to the
user's terminal.
With an 80 column terminal, a file name length of more than 35
characters would generate this problem.
To address this, we now set a minimum progress bar length, and
truncate the user's file name as needed.
This has been tested with large filenames and small terminals, and
at least produces reasonable results. If the terminal is too
narrow, the progress display takes up an additional line with each
update, but this is more user friendly than writing garbage to the
tty."
To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/bsd/progress/dist/progress.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: othersrc/external/bsd/progress/dist/progress.c
diff -u othersrc/external/bsd/progress/dist/progress.c:1.1.1.1 othersrc/external/bsd/progress/dist/progress.c:1.2
--- othersrc/external/bsd/progress/dist/progress.c:1.1.1.1 Mon May 7 03:36:58 2012
+++ othersrc/external/bsd/progress/dist/progress.c Tue Sep 1 03:47:28 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: progress.c,v 1.1.1.1 2012/05/07 03:36:58 agc Exp $ */
+/* $NetBSD: progress.c,v 1.2 2015/09/01 03:47:28 agc Exp $ */
/*-
* Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -126,6 +126,7 @@ progress_complete(progress_t *prog, uint
int
progress_draw(progress_t *prog, uint64_t done)
{
+#define MIN_BAR_LENGTH 10
#define BAROVERHEAD 45 /* non `*' portion of progress bar */
/*
* stars should contain at least
@@ -141,7 +142,9 @@ progress_draw(progress_t *prog, uint64_t
uint64_t bytespersec;
uint64_t abbrevsize;
int64_t secsleft;
- size_t barlength;
+ ssize_t tmpprefixlength;
+ ssize_t barlength;
+ size_t prefixlength;
size_t starc;
char hours[12];
char buf[256];
@@ -153,7 +156,18 @@ progress_draw(progress_t *prog, uint64_t
if (done != 0) {
progress_update(prog, done);
}
- barlength = MIN(sizeof(buf) - 1, (unsigned)prog->ttywidth) - BAROVERHEAD - strlen(prog->prefix);
+ prefixlength = strlen(prog->prefix);
+ barlength = MIN(sizeof(buf) - 1, (unsigned)prog->ttywidth) - BAROVERHEAD - prefixlength;
+ if (barlength < MIN_BAR_LENGTH) {
+ /*
+ * the tty width is too small, or the prefix is too large, for
+ * the progress bar. Decrease the prefix length
+ */
+ barlength = MIN_BAR_LENGTH;
+ tmpprefixlength = MIN(sizeof(buf) - 1, (unsigned)prog->ttywidth) -
+ BAROVERHEAD - MIN_BAR_LENGTH;
+ prefixlength = (tmpprefixlength > 0) ? tmpprefixlength : 0;
+ }
starc = (barlength * prog->percent) / 100;
abbrevsize = prog->done;
for (bytesabbrev = 0; abbrevsize >= 100000 && bytesabbrev < NSUFFIXES; bytesabbrev++) {