]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_cb_prg: output "flying saucers" with leading carriage return
authorDaniel Stenberg <daniel@haxx.se>
Sat, 20 Jul 2024 21:21:16 +0000 (23:21 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 22 Jul 2024 15:33:18 +0000 (17:33 +0200)
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

src/tool_cb_prg.c

index 865e9cec9950beda8f6f71d90f9d501620684404..4c3d3cdb5a0fb765ac1911f785112c78015ff251 100644 (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);