From 9870b80f81789d45744a6639d97c5f1595f9fd70 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 25 Jan 2020 16:46:41 +0100 Subject: curl: make the -# spaceship bar not wrap the line The fixed-point math made us lose precision and thus a too high index value could be used for outputting the hashtags which could overwrite the newline. The fix increases the precision in the sine table (*100) and the associated position math. Reported-by: Andrew Potter Fixes #4849 Closes #4850 --- src/tool_cb_prg.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/tool_cb_prg.c b/src/tool_cb_prg.c index d4c146590..aad451b87 100644 --- a/src/tool_cb_prg.c +++ b/src/tool_cb_prg.c @@ -46,25 +46,32 @@ my $pi = 3.1415; foreach my $i (1 .. 200) { - printf "%d, ", sin($i/200 * 2 * $pi) * 5000 + 5000; + printf "%d, ", sin($i/200 * 2 * $pi) * 500000 + 500000; } */ static const unsigned int sinus[] = { - 5157, 5313, 5470, 5626, 5782, 5936, 6090, 6243, 6394, 6545, 6693, 6840, 6985, - 7128, 7269, 7408, 7545, 7679, 7810, 7938, 8064, 8187, 8306, 8422, 8535, 8644, - 8750, 8852, 8950, 9045, 9135, 9221, 9303, 9381, 9454, 9524, 9588, 9648, 9704, - 9755, 9801, 9842, 9879, 9911, 9938, 9960, 9977, 9990, 9997, 9999, 9997, 9990, - 9977, 9960, 9938, 9911, 9879, 9842, 9801, 9755, 9704, 9648, 9588, 9524, 9455, - 9381, 9303, 9221, 9135, 9045, 8950, 8852, 8750, 8645, 8535, 8422, 8306, 8187, - 8064, 7939, 7810, 7679, 7545, 7409, 7270, 7129, 6986, 6841, 6694, 6545, 6395, - 6243, 6091, 5937, 5782, 5627, 5470, 5314, 5157, 5000, 4843, 4686, 4529, 4373, - 4218, 4063, 3909, 3757, 3605, 3455, 3306, 3159, 3014, 2871, 2730, 2591, 2455, - 2321, 2190, 2061, 1935, 1813, 1693, 1577, 1464, 1355, 1249, 1147, 1049, 955, - 864, 778, 696, 618, 545, 476, 411, 351, 295, 244, 198, 157, 120, 88, 61, 39, - 22, 9, 2, 0, 2, 9, 22, 39, 61, 88, 120, 156, 198, 244, 295, 350, 410, 475, - 544, 618, 695, 777, 864, 954, 1048, 1146, 1248, 1354, 1463, 1576, 1692, 1812, - 1934, 2060, 2188, 2320, 2454, 2590, 2729, 2870, 3013, 3158, 3305, 3454, 3604, - 3755, 3908, 4062, 4216, 4372, 4528, 4685, 4842, 4999 + 515704, 531394, 547052, 562664, 578214, 593687, 609068, 624341, 639491, + 654504, 669364, 684057, 698568, 712883, 726989, 740870, 754513, 767906, + 781034, 793885, 806445, 818704, 830647, 842265, 853545, 864476, 875047, + 885248, 895069, 904500, 913532, 922156, 930363, 938145, 945495, 952406, + 958870, 964881, 970434, 975522, 980141, 984286, 987954, 991139, 993840, + 996054, 997778, 999011, 999752, 999999, 999754, 999014, 997783, 996060, + 993848, 991148, 987964, 984298, 980154, 975536, 970449, 964898, 958888, + 952426, 945516, 938168, 930386, 922180, 913558, 904527, 895097, 885277, + 875077, 864507, 853577, 842299, 830682, 818739, 806482, 793922, 781072, + 767945, 754553, 740910, 727030, 712925, 698610, 684100, 669407, 654548, + 639536, 624386, 609113, 593733, 578260, 562710, 547098, 531440, 515751, + 500046, 484341, 468651, 452993, 437381, 421830, 406357, 390976, 375703, + 360552, 345539, 330679, 315985, 301474, 287158, 273052, 259170, 245525, + 232132, 219003, 206152, 193590, 181331, 169386, 157768, 146487, 135555, + 124983, 114781, 104959, 95526, 86493, 77868, 69660, 61876, 54525, 47613, + 41147, 35135, 29581, 24491, 19871, 15724, 12056, 8868, 6166, 3951, 2225, + 990, 248, 0, 244, 982, 2212, 3933, 6144, 8842, 12025, 15690, 19832, 24448, + 29534, 35084, 41092, 47554, 54462, 61809, 69589, 77794, 86415, 95445, + 104873, 114692, 124891, 135460, 146389, 157667, 169282, 181224, 193480, + 206039, 218888, 232015, 245406, 259048, 272928, 287032, 301346, 315856, + 330548, 345407, 360419, 375568, 390841, 406221, 421693, 437243, 452854, + 468513, 484202, 499907 }; static void fly(struct ProgressData *bar, bool moved) @@ -76,13 +83,13 @@ static void fly(struct ProgressData *bar, bool moved) msnprintf(buf, sizeof(buf), "%*s\r", bar->width-1, " "); memcpy(&buf[bar->bar], "-=O=-", 5); - pos = sinus[bar->tick%200] / (10000 / check); + pos = sinus[bar->tick%200] / (1000000 / check); buf[pos] = '#'; - pos = sinus[(bar->tick + 5)%200] / (10000 / check); + pos = sinus[(bar->tick + 5)%200] / (1000000 / check); buf[pos] = '#'; - pos = sinus[(bar->tick + 10)%200] / (10000 / check); + pos = sinus[(bar->tick + 10)%200] / (1000000 / check); buf[pos] = '#'; - pos = sinus[(bar->tick + 15)%200] / (10000 / check); + pos = sinus[(bar->tick + 15)%200] / (1000000 / check); buf[pos] = '#'; fputs(buf, bar->out); -- cgit v1.2.3