From c905459e878690942e9a0a8cd7f9ad57b6898efb Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 31 Aug 2021 14:09:28 +0200 Subject: [PATCH] progress: make trspeed avoid floats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and compiler warnings for data conversions. Reported-by: MichaƂ Antoniak Fixes #7645 Closes #7653 --- lib/progress.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/progress.c b/lib/progress.c index 62e61d45b4..f5ef6bd526 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -377,7 +377,12 @@ static curl_off_t trspeed(curl_off_t size, /* number of bytes */ { if(us < 1) return size * 1000000; - return (curl_off_t)((long double)size/(long double)us * 1000000); + else if(size < CURL_OFF_T_MAX/1000000) + return (size * 1000000) / us; + else if(us >= 1000000) + return size / (us / 1000000); + else + return CURL_OFF_T_MAX; } /* returns TRUE if it's time to show the progress meter */