tool_cb_prg: output "flying saucers" with leading carriage return

Because that is how the progress-bar is output, so when the progress-bar
has been shown at least once and the information is reset, like for a
redirect, there might be a moment where the size goes from known to
unknown and then the flying saucerts are shown after a brief display of
the progress-bar.

It could previously cause accidental character leftovers on the right
side of the bar when using a narrow display.

Reported-by: Chris Webb
Fixes #14213
Closes #14246
This commit is contained in:
Daniel Stenberg 2024-07-20 23:21:16 +02:00
parent eef17551ac
commit 8193ca59e1
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -77,19 +77,19 @@ static void fly(struct ProgressData *bar, bool moved)
/* bar->width is range checked when assigned */
DEBUGASSERT(bar->width <= MAX_BARLENGTH);
memset(buf, ' ', bar->width);
buf[bar->width] = '\r';
buf[0] = '\r';
memset(&buf[1], ' ', bar->width);
buf[bar->width + 1] = '\0';
memcpy(&buf[bar->bar], "-=O=-", 5);
memcpy(&buf[bar->bar + 1], "-=O=-", 5);
pos = sinus[bar->tick%200] / (1000000 / check);
pos = sinus[bar->tick%200] / (1000000 / check) + 1;
buf[pos] = '#';
pos = sinus[(bar->tick + 5)%200] / (1000000 / check);
pos = sinus[(bar->tick + 5)%200] / (1000000 / check) + 1;
buf[pos] = '#';
pos = sinus[(bar->tick + 10)%200] / (1000000 / check);
pos = sinus[(bar->tick + 10)%200] / (1000000 / check) + 1;
buf[pos] = '#';
pos = sinus[(bar->tick + 15)%200] / (1000000 / check);
pos = sinus[(bar->tick + 15)%200] / (1000000 / check) + 1;
buf[pos] = '#';
fputs(buf, bar->out);