From 6ffaf3bd22a0080c07d9c6b9d3aaf25a8a351d11 Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Sun, 8 Jun 2025 22:55:55 +0200 Subject: [PATCH] fix: Do not crash due to unavailable tracks in queue * fix: Do not crash due to unavailable tracks in queue Fixes #1616 * fix: Also use checked multiplication to prevent overflow --- CHANGELOG.md | 1 + src/ui/statusbar.rs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78f3f4f..9474603 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Skip unplayable tracks - Queue UI correctly plays a track when clicking on an already selected item - Swap foreground and background colors for command line input +- Do not crash due to unavailable tracks in queue ## [1.2.2] diff --git a/src/ui/statusbar.rs b/src/ui/statusbar.rs index e4800ba..8bbfb63 100644 --- a/src/ui/statusbar.rs +++ b/src/ui/statusbar.rs @@ -190,8 +190,10 @@ impl View for StatusBar { if let Some(t) = self.queue.get_current() { printer.with_color(style_bar, |printer| { - let duration_width = - (((printer.size.x as u32) * elapsed_ms) / t.duration()) as usize; + let duration_width = elapsed_ms + .checked_mul(printer.size.x as u32) + .and_then(|v| v.checked_div(t.duration())) + .unwrap_or(0) as usize; printer.print((0, 0), &"━".repeat(duration_width + 1)); }); }