[vlc-commits] ActiveX/NPAPI: Don't return -1 for count properties (refs #14752)
Daniel Amm
git at videolan.org
Mon Oct 10 23:42:48 CEST 2016
npapi-vlc | branch: master | Daniel Amm <da2424 at t-online.de> | Thu Oct 6 18:02:54 2016 +0200| [df2c5327fd719192ad625e9039cac8c4857911e6] | committer: Jean-Baptiste Kempf
ActiveX/NPAPI: Don't return -1 for count properties (refs #14752)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> https://code.videolan.org/videolan/npapi-vlc/commit/df2c5327fd719192ad625e9039cac8c4857911e6
---
activex/vlccontrol2.cpp | 10 ++++++----
npapi/npruntime/npolibvlc.cpp | 8 ++++----
npapi/npruntime/nporuntime.h | 5 +++++
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/activex/vlccontrol2.cpp b/activex/vlccontrol2.cpp
index 69e8368..90a8d46 100644
--- a/activex/vlccontrol2.cpp
+++ b/activex/vlccontrol2.cpp
@@ -90,6 +90,8 @@ HRESULT object_get(I **dst, I *src)
static inline
VARIANT_BOOL varbool(bool b) { return b ? VARIANT_TRUE : VARIANT_FALSE; }
+static inline INT negativeToZero(int i) { return i < 0 ? 0 : i; }
+
static HRESULT parseStringOptions(int codePage, BSTR bstr, char*** cOptions, int *cOptionCount)
{
HRESULT hr = E_INVALIDARG;
@@ -464,7 +466,7 @@ STDMETHODIMP VLCAudio::get_count(long* trackNumber)
if( NULL == trackNumber )
return E_POINTER;
- *trackNumber = _plug->get_player().get_mp().audioTrackCount();
+ *trackNumber = negativeToZero( _plug->get_player().get_mp().audioTrackCount() );
return S_OK;
}
@@ -530,7 +532,7 @@ STDMETHODIMP VLCTitle::get_count(long* countTracks)
if( NULL == countTracks )
return E_POINTER;
- *countTracks = _plug->get_player().get_mp().titleCount();
+ *countTracks = negativeToZero( _plug->get_player().get_mp().titleCount() );
return S_OK;
}
@@ -568,7 +570,7 @@ STDMETHODIMP VLCChapter::get_count(long* countTracks)
if( NULL == countTracks )
return E_POINTER;
- *countTracks = _plug->get_player().get_mp().chapterCount();
+ *countTracks = negativeToZero( _plug->get_player().get_mp().chapterCount() );
return S_OK;
}
@@ -577,7 +579,7 @@ STDMETHODIMP VLCChapter::countForTitle(long track, long* countTracks)
if( NULL == countTracks )
return E_POINTER;
- *countTracks = _plug->get_player().get_mp().chapterCountForTitle(track);
+ *countTracks = negativeToZero( _plug->get_player().get_mp().chapterCountForTitle(track) );
return S_OK;
}
diff --git a/npapi/npruntime/npolibvlc.cpp b/npapi/npruntime/npolibvlc.cpp
index 16e6d06..820c638 100644
--- a/npapi/npruntime/npolibvlc.cpp
+++ b/npapi/npruntime/npolibvlc.cpp
@@ -262,7 +262,7 @@ LibvlcAudioNPObject::getProperty(int index, npapi::OutVariant& result)
}
case ID_audio_count:
{
- result = mp.audioTrackCount();
+ result = negativeToZero( mp.audioTrackCount() );
return INVOKERESULT_NO_ERROR;
}
case ID_audio_channel:
@@ -1975,7 +1975,7 @@ LibvlcTitleNPObject::getProperty(int index, npapi::OutVariant& result)
{
case ID_title_count:
{
- result = mp.titleCount();
+ result = negativeToZero( mp.titleCount() );
return INVOKERESULT_NO_ERROR;
}
case ID_title_track:
@@ -2099,7 +2099,7 @@ LibvlcChapterNPObject::getProperty(int index, npapi::OutVariant& result)
{
case ID_chapter_count:
{
- result = mp.chapterCount();
+ result = negativeToZero( mp.chapterCount() );
return INVOKERESULT_NO_ERROR;
}
case ID_chapter_track:
@@ -2181,7 +2181,7 @@ LibvlcChapterNPObject::invoke(int index, const NPVariant *args,
const npapi::Variant v( args[0] );
if( v.is<int>() )
{
- result = mp.chapterCountForTitle( v );
+ result = negativeToZero( mp.chapterCountForTitle( v ) );
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_NO_SUCH_METHOD;
diff --git a/npapi/npruntime/nporuntime.h b/npapi/npruntime/nporuntime.h
index 2ea80fd..4f44953 100644
--- a/npapi/npruntime/nporuntime.h
+++ b/npapi/npruntime/nporuntime.h
@@ -49,6 +49,11 @@ public:
// ownership problems with firefox.
template<class T> void InstantObj( NPObject *&obj );
+ inline int negativeToZero( int i )
+ {
+ return i < 0 ? 0 : i;
+ }
+
bool isValid()
{
return _instance != NULL;
More information about the vlc-commits
mailing list