From 5acfc853d8f36f5abc8068be140ab806259fcbd7 Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Thu, 12 Oct 2023 18:32:54 +0530 Subject: [PATCH] fix: usize multiplication overflow on 32bit machines 99 * 571421193 overflows --- uplink/src/collector/downloader.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uplink/src/collector/downloader.rs b/uplink/src/collector/downloader.rs index 08407c5f1..234cfa495 100644 --- a/uplink/src/collector/downloader.rs +++ b/uplink/src/collector/downloader.rs @@ -383,7 +383,8 @@ impl DownloadState { let size = human_bytes(self.content_length as f64); // Calculate percentage on the basis of content_length - let percentage = (99 * self.bytes_downloaded / self.content_length) as u8; + let factor = self.bytes_downloaded as f32 / self.content_length as f32; + let percentage = (99.99 * factor) as u8; // NOTE: ensure lesser frequency of action responses, once every percentage points if percentage > self.percentage_downloaded {