[Android] medialibrary: utils: Don't reassign NULL to a NULL initialized value
Hugo Beauzée-Luyssen
git at videolan.org
Mon Sep 27 09:18:54 UTC 2021
vlc-android | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Sep 24 11:30:28 2021 +0200| [8ef33a4e3192733c4bcc4518663acd7b0cd73396] | committer: Nicolas Pomepuy
medialibrary: utils: Don't reassign NULL to a NULL initialized value
This simplifies the code and will avoid useless calls once we switch to
a RAII enabled type
> https://code.videolan.org/videolan/vlc-android/commit/8ef33a4e3192733c4bcc4518663acd7b0cd73396
---
medialibrary/jni/utils.cpp | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index 898fa3281..4354e55a3 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -51,14 +51,18 @@ mediaToMediaWrapper(JNIEnv* env, fields *fields, medialibrary::MediaPtr const& m
jint audioTrack = metaAudioTrack.isSet() ? metaAudioTrack.asInt() : -2;
const medialibrary::IMetadata& metaSpuTrack = mediaPtr->metadata(medialibrary::IMedia::MetadataType::SubtitleTrack);
jint spuTrack = metaSpuTrack.isSet() ? metaSpuTrack.asInt() : -2;
- title = mediaPtr->title().empty() ? NULL : vlcNewStringUTF(env, mediaPtr->title().c_str());
- filename = mediaPtr->fileName().empty() ? NULL : vlcNewStringUTF(env, mediaPtr->fileName().c_str());
+ if (!mediaPtr->title().empty())
+ title = vlcNewStringUTF(env, mediaPtr->title().c_str());
+ if (!mediaPtr->fileName().empty())
+ filename = vlcNewStringUTF(env, mediaPtr->fileName().c_str());
try {
mrl = vlcNewStringUTF(env, files.at(0)->mrl().c_str());
} catch(const medialibrary::fs::errors::DeviceRemoved&) {
return nullptr;
}
- thumbnail = mediaPtr->thumbnailMrl(medialibrary::ThumbnailSizeType::Thumbnail).empty() ? NULL : vlcNewStringUTF(env, mediaPtr->thumbnailMrl(medialibrary::ThumbnailSizeType::Thumbnail).c_str());
+ auto thumbnailStr = mediaPtr->thumbnailMrl(medialibrary::ThumbnailSizeType::Thumbnail);
+ if (!thumbnailStr.empty())
+ thumbnail = vlcNewStringUTF(env, thumbnailStr.c_str());
std::vector<medialibrary::VideoTrackPtr> videoTracks = mediaPtr->videoTracks()->all();
bool hasVideoTracks = !videoTracks.empty();
unsigned int width = hasVideoTracks ? videoTracks.at(0)->width() : 0;
@@ -336,4 +340,3 @@ vlcNewStringUTF(JNIEnv* env, const char* psz_string)
}
return env->NewStringUTF(psz_string);
}
-
More information about the Android
mailing list