Fix integer overflow in refresh time calculation
match state.is_playing {
true => {
let track_end = match state.progress_ms {
- Some(prog) => state.item.duration_ms - prog,
+ Some(prog) => {
+ if prog < state.item.duration_ms {
+ state.item.duration_ms - prog
+ }
+ else {
+ 0
+ }
+ },
None => state.item.duration_ms,
} as i64;
// Refresh 1 second after track ends
}
None => REFRESH_PERIOD,
};
+ let refresh_offset = std::cmp::min(REFRESH_PERIOD, refresh_offset) as i64;
println!("State refresh in {} seconds.", refresh_offset);
- now + std::cmp::min(REFRESH_PERIOD, refresh_offset) as i64
+ now + refresh_offset
}
fn main() {