From ef27b6b6a78a59b603ac858de2c88f75b743f432 Mon Sep 17 00:00:00 2001 From: Dzhos Oleksii <35292229+Programistich@users.noreply.github.com> Date: Wed, 15 Nov 2023 15:19:49 +0200 Subject: [PATCH] Progress wrapper division by zero (#740) **Background** Now we have crash when file size equals **Changes** * Check divisions by zero, so set max percentage **Test plan** * Try use .mfkey32.log size equals zero Fix #739 --- CHANGELOG.md | 3 ++- .../core/progress/ProgressWrapperTracker.kt | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 622addad43..4a14720851 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ - [Feature] Optimization FapHub by compose metrics - [Feature] Firmware update notification - [FIX] Splashscreen WearOS icon -- [FIX] Handle expired link +- [FIX] Handle expired link +- [FIX] Progress wrapper division by zero # 1.6.6 diff --git a/components/core/progress/src/main/java/com/flipperdevices/core/progress/ProgressWrapperTracker.kt b/components/core/progress/src/main/java/com/flipperdevices/core/progress/ProgressWrapperTracker.kt index 426d50e2af..c16e494d9a 100644 --- a/components/core/progress/src/main/java/com/flipperdevices/core/progress/ProgressWrapperTracker.kt +++ b/components/core/progress/src/main/java/com/flipperdevices/core/progress/ProgressWrapperTracker.kt @@ -32,6 +32,14 @@ class ProgressWrapperTracker( } return } + if (max == 0L) { + onProgress(MAX_PERCENT) + if (BuildConfig.DEBUG) { + error("Max is zero") + } + return + } + val percent = current.toDouble() / max onProgress(percent.toFloat()) }