From 5330295a975e9daded99470133c87791c535630f Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 10 Feb 2022 01:14:42 -0800 Subject: [PATCH] Fix array bounds issues with album shuffle builder The shuffle list builder was encountering errors when some album tags or empty album tags led to empty lists. Signed-off-by: Christopher Snowhill --- Playlist/PlaylistController.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index 6b48b3fc2..bed0319d7 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -894,7 +894,7 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc if([album length] > 0) predicate = [NSPredicate predicateWithFormat:@"album like %@", album]; else - predicate = [NSPredicate predicateWithFormat:@"album == nil"]; + predicate = [NSPredicate predicateWithFormat:@"album == nil || album like %@", @""]; return [[self arrangedObjects] filteredArrayUsingPredicate:predicate]; } @@ -960,7 +960,8 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc NSArray *albumContent = [self filterPlaylistOnAlbum:album]; NSArray *sortedContent = [albumContent sortedArrayUsingDescriptors:@[sortDescriptor]]; - [temp addObject:sortedContent[0]]; + if(sortedContent && [sortedContent count]) + [temp addObject:sortedContent[0]]; } NSArray *tempList = [Shuffle shuffleList:temp]; temp = [[NSMutableArray alloc] init]; @@ -970,7 +971,8 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc NSArray *albumContent = [self filterPlaylistOnAlbum:album]; NSArray *sortedContent = [albumContent sortedArrayUsingDescriptors:@[sortDescriptor]]; - [temp addObjectsFromArray:sortedContent]; + if(sortedContent && [sortedContent count]) + [temp addObjectsFromArray:sortedContent]; } return temp; }