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
This commit is contained in:
Henrik Friedrichsen
2025-06-08 22:55:55 +02:00
committed by GitHub
parent 46eb9dc1dd
commit 6ffaf3bd22
2 changed files with 5 additions and 2 deletions

View File

@@ -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]

View File

@@ -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));
});
}