[Android] Prevent crash when check for deleted playlist size

Geoffrey Métais git at videolan.org
Thu Sep 13 16:15:15 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Sep 13 16:11:25 2018 +0200| [0c835fd959dc1210e93508d70528a6f5e598fdfa] | committer: Geoffrey Métais

Prevent crash when check for deleted playlist size

> https://code.videolan.org/videolan/vlc-android/commit/0c835fd959dc1210e93508d70528a6f5e598fdfa
---

 medialibrary/jni/medialibrary.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index c4e58f43f..806abe0d7 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -959,7 +959,8 @@ getTracksFromAlbum(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, ji
 
 jint
 getTracksFromAlbumCount(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id) {
-    return (jint) MediaLibrary_getInstance(env, medialibrary)->tracksFromAlbum(id, nullptr)->count();
+    const auto query = MediaLibrary_getInstance(env, medialibrary)->tracksFromAlbum(id, nullptr);
+    return (jint) (query!= nullptr ? query->count() : 0);
 }
 
 jobjectArray
@@ -1459,6 +1460,7 @@ getPagedMediaFromPlaylist(JNIEnv* env, jobject thiz, jobject medialibrary, jlong
 {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
     const auto query = aml->mediaFromPlaylist(id);
+    if (query == nullptr) return (jobjectArray) env->NewObjectArray(0, ml_fields.MediaWrapper.clazz, NULL);
     std::vector<medialibrary::MediaPtr> mediaList = nbItems != 0 ? query->items(nbItems, offset) : query->all();
     jobjectArray mediaRefs = (jobjectArray) env->NewObjectArray(mediaList.size(), ml_fields.MediaWrapper.clazz, NULL);
     int index = -1;
@@ -1472,7 +1474,8 @@ getPagedMediaFromPlaylist(JNIEnv* env, jobject thiz, jobject medialibrary, jlong
 
 jint
 getPlaylistTracksCount(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id) {
-    return (jint) MediaLibrary_getInstance(env, medialibrary)->mediaFromPlaylist(id)->count();
+    const auto query = MediaLibrary_getInstance(env, medialibrary)->mediaFromPlaylist(id);
+    return (jint) (query != nullptr ? query->count() : 0);
 }
 
 jobjectArray



More information about the Android mailing list