From: Daniel Stenberg Date: Mon, 10 Feb 2025 09:15:44 +0000 (+0100) Subject: tool_progress: fix percent output of large parallel transfers X-Git-Tag: curl-8_12_1~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48df83a30e7d032ae3354d4b06e758ceb4210775;p=thirdparty%2Fcurl.git tool_progress: fix percent output of large parallel transfers When the total transfered amount (upload or download) for parallel transfers was larger than 2^63/100 bytes (81 petabytes) the progress percent counter would show wrong. Closes #16284 --- diff --git a/src/tool_progress.c b/src/tool_progress.c index 3fac70a70e..c4df2111ae 100644 --- a/src/tool_progress.c +++ b/src/tool_progress.c @@ -216,13 +216,16 @@ bool progress_meter(struct GlobalConfig *global, all_running++; } if(dlknown && all_dltotal) - /* TODO: handle integer overflow */ msnprintf(dlpercen, sizeof(dlpercen), "%3" CURL_FORMAT_CURL_OFF_T, - all_dlnow * 100 / all_dltotal); + all_dlnow < (CURL_OFF_T_MAX/100) ? + (all_dlnow * 100 / all_dltotal) : + (all_dlnow / (all_dltotal/100))); + if(ulknown && all_ultotal) - /* TODO: handle integer overflow */ msnprintf(ulpercen, sizeof(ulpercen), "%3" CURL_FORMAT_CURL_OFF_T, - all_ulnow * 100 / all_ultotal); + all_ulnow < (CURL_OFF_T_MAX/100) ? + (all_ulnow * 100 / all_ultotal) : + (all_ulnow / (all_ultotal/100))); /* get the transfer speed, the higher of the two */