[vlc-commits] Ensure we are not wrapping a null libvlc_media_t
Hugo Beauzée-Luyssen
git at videolan.org
Mon May 25 10:04:45 CEST 2015
libvlcpp | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed May 20 10:58:44 2015 +0200| [0a99e452de307c08aa782e58308f3929fcc4edac] | committer: Hugo Beauzée-Luyssen
Ensure we are not wrapping a null libvlc_media_t
> http://git.videolan.org/gitweb.cgi/libvlcpp.git/?a=commit;h=0a99e452de307c08aa782e58308f3929fcc4edac
---
vlcpp/EventManager.hpp | 2 +-
vlcpp/Media.hpp | 5 +++++
vlcpp/MediaList.hpp | 2 ++
vlcpp/MediaPlayer.hpp | 4 +++-
4 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/vlcpp/EventManager.hpp b/vlcpp/EventManager.hpp
index c92d370..f4a723f 100644
--- a/vlcpp/EventManager.hpp
+++ b/vlcpp/EventManager.hpp
@@ -724,7 +724,7 @@ class MediaListEventManager : public EventManager
{
auto callback = static_cast<DecayPtr<Func>>( data );
auto media = e->u.media_list_will_add_item.item;
- (*callback)(media != nullptr ? std::make_shared<Media>( media, true ) : nullptr,
+ (*callback)( media != nullptr ? std::make_shared<Media>( media, true ) : nullptr,
e->u.media_list_will_add_item.index );
});
}
diff --git a/vlcpp/Media.hpp b/vlcpp/Media.hpp
index 4aa0be3..4a34ef4 100644
--- a/vlcpp/Media.hpp
+++ b/vlcpp/Media.hpp
@@ -363,6 +363,11 @@ public:
Media duplicate()
{
auto obj = libvlc_media_duplicate(*this);
+ // Assume failure to duplicate is due to VLC_ENOMEM.
+ // libvlc_media_duplicate(nullptr) would also return nullptr, but
+ // we consider the use of an empty libvlcpp instance undefined.
+ if ( obj == nullptr )
+ throw std::bad_alloc();
return Media( obj, false );
}
diff --git a/vlcpp/MediaList.hpp b/vlcpp/MediaList.hpp
index 2e053ec..7474416 100644
--- a/vlcpp/MediaList.hpp
+++ b/vlcpp/MediaList.hpp
@@ -171,6 +171,8 @@ public:
MediaPtr itemAtIndex(int i_pos)
{
auto ptr = libvlc_media_list_item_at_index(*this,i_pos);
+ if ( ptr == nullptr )
+ return nullptr;
return std::make_shared<Media>( ptr, false );
}
diff --git a/vlcpp/MediaPlayer.hpp b/vlcpp/MediaPlayer.hpp
index 3e90f70..ff7f119 100644
--- a/vlcpp/MediaPlayer.hpp
+++ b/vlcpp/MediaPlayer.hpp
@@ -124,7 +124,9 @@ public:
*/
MediaPtr media()
{
- libvlc_media_t* media = libvlc_media_player_get_media(*this);
+ auto media = libvlc_media_player_get_media(*this);
+ if ( media == nullptr )
+ return nullptr;
return std::make_shared<Media>( media, true );
}
More information about the vlc-commits
mailing list