mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Merge pull request #880 from JasonLG1979/fix_index_out_bounds_spirc
Guard against tracks_len being zero
This commit is contained in:
commit
e064f27c13
1 changed files with 8 additions and 0 deletions
|
@ -1140,6 +1140,14 @@ impl SpircTask {
|
||||||
fn get_track_id_to_play_from_playlist(&self, index: u32) -> Option<(SpotifyId, u32)> {
|
fn get_track_id_to_play_from_playlist(&self, index: u32) -> Option<(SpotifyId, u32)> {
|
||||||
let tracks_len = self.state.get_track().len();
|
let tracks_len = self.state.get_track().len();
|
||||||
|
|
||||||
|
// Guard against tracks_len being zero to prevent
|
||||||
|
// 'index out of bounds: the len is 0 but the index is 0'
|
||||||
|
// https://github.com/librespot-org/librespot/issues/226#issuecomment-971642037
|
||||||
|
if tracks_len == 0 {
|
||||||
|
warn!("No playable track found in state: {:?}", self.state);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let mut new_playlist_index = index as usize;
|
let mut new_playlist_index = index as usize;
|
||||||
|
|
||||||
if new_playlist_index >= tracks_len {
|
if new_playlist_index >= tracks_len {
|
||||||
|
|
Loading…
Reference in a new issue