[vlc-commits] medialibrary: Don't assume query to be non-null

Hugo Beauzée-Luyssen git at videolan.org
Wed Jan 23 10:01:35 CET 2019


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Aug  3 16:50:49 2018 +0200| [ad6c3cd6ddb1633ccf01791bab8ae199b647ef04] | committer: Hugo Beauzée-Luyssen

medialibrary: Don't assume query to be non-null

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ad6c3cd6ddb1633ccf01791bab8ae199b647ef04
---

 modules/misc/medialibrary/medialib.cpp | 52 ++++++++++++++++++++++++++++++++--
 1 file changed, 50 insertions(+), 2 deletions(-)

diff --git a/modules/misc/medialibrary/medialib.cpp b/modules/misc/medialibrary/medialib.cpp
index 85689e26d5..c5245c81b5 100644
--- a/modules/misc/medialibrary/medialib.cpp
+++ b/modules/misc/medialibrary/medialib.cpp
@@ -514,6 +514,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
                 query = m_ml->searchVideo( psz_pattern, paramsPtr );
             else
                 query = m_ml->videoFiles( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             auto res = ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
                         query->items( nbItems, offset ) );
             *va_arg( args, vlc_ml_media_list_t**) = res;
@@ -526,6 +528,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
                 query = m_ml->searchVideo( psz_pattern, paramsPtr );
             else
                 query = m_ml->videoFiles( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             *va_arg( args, size_t* ) = query->count();
             break;
         }
@@ -536,6 +540,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
                 query = m_ml->searchAudio( psz_pattern, paramsPtr );
             else
                 query = m_ml->audioFiles( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             auto res = ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
                         query->items( nbItems, offset ) );
             *va_arg( args, vlc_ml_media_list_t**) = res;
@@ -548,6 +554,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
                 query = m_ml->searchAudio( psz_pattern, paramsPtr );
             else
                 query = m_ml->audioFiles( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             *va_arg( args, size_t* ) = query->count();
             break;
         }
@@ -558,6 +566,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
                 query = m_ml->searchAlbums( psz_pattern, paramsPtr );
             else
                 query = m_ml->albums( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             auto res = ml_convert_list<vlc_ml_album_list_t, vlc_ml_album_t>(
                         query->items( nbItems, offset ) );
             *va_arg( args, vlc_ml_album_list_t**) = res;
@@ -570,6 +580,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
                 query = m_ml->searchAlbums( psz_pattern, paramsPtr );
             else
                 query = m_ml->albums( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             *va_arg( args, size_t* ) = query->count();
             break;
         }
@@ -580,6 +592,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
                 query = m_ml->searchGenre( psz_pattern, paramsPtr );
             else
                 query = m_ml->genres( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             auto res = ml_convert_list<vlc_ml_genre_list_t,vlc_ml_genre_t>(
                         query->items( nbItems, offset ) );
             *va_arg( args, vlc_ml_genre_list_t**) = res;
@@ -592,6 +606,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
                 query = m_ml->searchGenre( psz_pattern, paramsPtr );
             else
                 query = m_ml->genres( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             *va_arg( args, size_t* ) = query->count();
             break;
         }
@@ -602,9 +618,9 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
             if ( psz_pattern != nullptr )
                 query = m_ml->searchArtists( psz_pattern, paramsPtr );
             else
-            {
                 query = m_ml->artists( includeAll, paramsPtr );
-            }
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             auto res = ml_convert_list<vlc_ml_artist_list_t, vlc_ml_artist_t>(
                         query->items( nbItems, offset ) );
             *va_arg( args, vlc_ml_artist_list_t**) = res;
@@ -618,6 +634,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
                 query = m_ml->searchArtists( psz_pattern, paramsPtr );
             else
                 query = m_ml->artists( includeAll, paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             *va_arg( args, size_t* ) = query->count();
             break;
         }
@@ -636,6 +654,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
             if ( media == nullptr )
                 return VLC_EGENERIC;
             auto query = media->labels();
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             switch ( listQuery )
             {
                 case VLC_ML_LIST_MEDIA_LABELS:
@@ -657,6 +677,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
                 query = m_ml->searchShows( psz_pattern, paramsPtr );
             else
                 query = m_ml->shows( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             *va_arg( args, vlc_ml_show_list_t** ) =
                     ml_convert_list<vlc_ml_show_list_t, vlc_ml_show_t>(
                         query->items( nbItems, offset ) );
@@ -665,6 +687,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
         case VLC_ML_COUNT_SHOWS:
         {
             auto query = m_ml->shows( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             *va_arg( args, int64_t* ) = query->count();
             return VLC_SUCCESS;
         }
@@ -679,6 +703,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
                 query = show->searchEpisodes( psz_pattern, paramsPtr );
             else
                 query = show->episodes( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             switch ( listQuery )
             {
                 case VLC_ML_LIST_SHOW_EPISODES:
@@ -701,6 +727,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
         case VLC_ML_LIST_HISTORY:
         {
             auto query = m_ml->history();
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             *va_arg( args, vlc_ml_media_list_t**) =
                     ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
                         query->items( nbItems, offset ) );
@@ -709,6 +737,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
         case VLC_ML_LIST_STREAM_HISTORY:
         {
             auto query = m_ml->streamHistory();
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             *va_arg( args, vlc_ml_media_list_t**) =
                     ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
                         query->items( nbItems, offset ) );
@@ -1034,6 +1064,8 @@ int MediaLibrary::listAlbums( int listQuery, const medialibrary::QueryParameters
                 query = album->searchTracks( pattern, paramsPtr );
             else
                 query = album->tracks( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             switch ( listQuery )
             {
                 case VLC_ML_LIST_ALBUM_TRACKS:
@@ -1052,6 +1084,8 @@ int MediaLibrary::listAlbums( int listQuery, const medialibrary::QueryParameters
         case VLC_ML_COUNT_ALBUM_ARTISTS:
         {
             auto query = album->artists( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             switch ( listQuery )
             {
                 case VLC_ML_LIST_ALBUM_ARTISTS:
@@ -1088,6 +1122,8 @@ int MediaLibrary::listArtists( int listQuery, const medialibrary::QueryParameter
                 query = artist->searchAlbums( pattern, paramsPtr );
             else
                 query = artist->albums( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             switch ( listQuery )
             {
                 case VLC_ML_LIST_ARTIST_ALBUMS:
@@ -1110,6 +1146,8 @@ int MediaLibrary::listArtists( int listQuery, const medialibrary::QueryParameter
                 query = artist->searchTracks( pattern, paramsPtr );
             else
                 query = artist->tracks( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             switch ( listQuery )
             {
                 case VLC_ML_LIST_ARTIST_TRACKS:
@@ -1145,6 +1183,8 @@ int MediaLibrary::listGenre( int listQuery, const medialibrary::QueryParameters*
                 query = genre->searchArtists( pattern, paramsPtr );
             else
                 query = genre->artists( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             switch ( listQuery )
             {
                 case VLC_ML_LIST_GENRE_ARTISTS:
@@ -1167,6 +1207,8 @@ int MediaLibrary::listGenre( int listQuery, const medialibrary::QueryParameters*
                 query = genre->searchTracks( pattern, paramsPtr );
             else
                 query = genre->tracks( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             switch ( listQuery )
             {
                 case VLC_ML_LIST_GENRE_TRACKS:
@@ -1189,6 +1231,8 @@ int MediaLibrary::listGenre( int listQuery, const medialibrary::QueryParameters*
                 query = genre->searchAlbums( pattern, paramsPtr );
             else
                 query = genre->albums( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             switch ( listQuery )
             {
                 case VLC_ML_LIST_GENRE_ALBUMS:
@@ -1221,6 +1265,8 @@ int MediaLibrary::listPlaylist( int listQuery, const medialibrary::QueryParamete
                 query = m_ml->searchPlaylists( pattern, paramsPtr );
             else
                 query = m_ml->playlists( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             switch ( listQuery )
             {
                 case VLC_ML_LIST_PLAYLISTS:
@@ -1246,6 +1292,8 @@ int MediaLibrary::listPlaylist( int listQuery, const medialibrary::QueryParamete
                 query = playlist->searchMedia( pattern, paramsPtr );
             else
                 query = playlist->media();
+            if ( query == nullptr )
+                return VLC_EGENERIC;
             switch ( listQuery )
             {
                 case VLC_ML_LIST_PLAYLIST_MEDIA:



More information about the vlc-commits mailing list