[vlc-commits] qt: fix incorrect param type
Lyndon Brown
git at videolan.org
Fri Sep 25 09:26:02 CEST 2020
vlc | branch: master | Lyndon Brown <jnqnfe at gmail.com> | Sat Sep 5 19:10:53 2020 +0100| [4c75da934016f67a9bc6334e67959b3615ee6c6d] | committer: Pierre Lamot
qt: fix incorrect param type
which was causing a whole bunch of "'< 0' is always false" warnings.
review of the original fix ([1]) indicated that in fact the parameter was
wrong rather than the checks within the function being out of step with
the final design of the function interface, since apparently callers
are in fact passing in a signed index, where a negative represents an
invalid index which the function is expected to handle appropriately.
[1]: https://mailman.videolan.org/pipermail/vlc-devel/2020-September/137711.html
Co-authored-by: Pierre Lamot <pierre at videolabs.io>
Signed-off-by: Pierre Lamot <pierre at videolabs.io>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4c75da934016f67a9bc6334e67959b3615ee6c6d
---
modules/gui/qt/medialibrary/mlalbummodel.cpp | 2 +-
modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp | 2 +-
modules/gui/qt/medialibrary/mlartistmodel.cpp | 2 +-
modules/gui/qt/medialibrary/mlbasemodel.hpp | 12 ++++++++----
modules/gui/qt/medialibrary/mlgenremodel.cpp | 2 +-
modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp | 2 +-
modules/gui/qt/medialibrary/mlvideomodel.cpp | 2 +-
7 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/modules/gui/qt/medialibrary/mlalbummodel.cpp b/modules/gui/qt/medialibrary/mlalbummodel.cpp
index dc044c28ef..2326c43718 100644
--- a/modules/gui/qt/medialibrary/mlalbummodel.cpp
+++ b/modules/gui/qt/medialibrary/mlalbummodel.cpp
@@ -38,7 +38,7 @@ QVariant MLAlbumModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || index.row() < 0)
return QVariant();
- const MLAlbum* ml_item = item(static_cast<unsigned int>(index.row()));
+ const MLAlbum* ml_item = item(index.row());
if ( ml_item == NULL )
return QVariant();
diff --git a/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp b/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
index ed4c63de7a..36db52cb26 100644
--- a/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
+++ b/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
@@ -59,7 +59,7 @@ QVariant MLAlbumTrackModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || index.row() < 0)
return QVariant();
- const MLAlbumTrack* ml_track = item(static_cast<unsigned int>(index.row()));
+ const MLAlbumTrack* ml_track = item(index.row());
if ( !ml_track )
return QVariant();
diff --git a/modules/gui/qt/medialibrary/mlartistmodel.cpp b/modules/gui/qt/medialibrary/mlartistmodel.cpp
index ec87c17b0c..ebb30d23e2 100644
--- a/modules/gui/qt/medialibrary/mlartistmodel.cpp
+++ b/modules/gui/qt/medialibrary/mlartistmodel.cpp
@@ -44,7 +44,7 @@ QVariant MLArtistModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || index.row() < 0)
return QVariant();
- const MLArtist* ml_artist = item(static_cast<unsigned int>(index.row()));
+ const MLArtist* ml_artist = item(index.row());
if ( !ml_artist )
return QVariant();
diff --git a/modules/gui/qt/medialibrary/mlbasemodel.hpp b/modules/gui/qt/medialibrary/mlbasemodel.hpp
index bbedc6c26e..326bd14117 100644
--- a/modules/gui/qt/medialibrary/mlbasemodel.hpp
+++ b/modules/gui/qt/medialibrary/mlbasemodel.hpp
@@ -162,7 +162,7 @@ public:
return m_total_count;
}
- virtual T* get(unsigned int idx) const
+ virtual T* get(int idx) const
{
vlc_mutex_locker lock( &m_item_lock );
T* obj = item( idx );
@@ -239,8 +239,12 @@ public:
}
protected:
- T* item(unsigned int idx) const
+ T* item(int signedidx) const
{
+ if (signedidx < 0)
+ return nullptr;
+
+ unsigned int idx = static_cast<unsigned int>(signedidx);
// Must be called in a locked context
if ( m_initialized == false )
{
@@ -251,7 +255,7 @@ protected:
emit countChanged( static_cast<unsigned int>(m_total_count) );
}
- if ( m_total_count == 0 || idx >= m_total_count || idx < 0 )
+ if ( m_total_count == 0 || idx >= m_total_count )
return nullptr;
if ( idx < m_query_param.i_offset || idx >= m_query_param.i_offset + m_item_list.size() )
@@ -264,7 +268,7 @@ protected:
}
//db has changed
- if ( idx - m_query_param.i_offset >= m_item_list.size() || idx - m_query_param.i_offset < 0 )
+ if ( idx - m_query_param.i_offset >= m_item_list.size() || idx < m_query_param.i_offset )
return nullptr;
return m_item_list[idx - m_query_param.i_offset].get();
}
diff --git a/modules/gui/qt/medialibrary/mlgenremodel.cpp b/modules/gui/qt/medialibrary/mlgenremodel.cpp
index a3f9a2dec6..639ce2e8ae 100644
--- a/modules/gui/qt/medialibrary/mlgenremodel.cpp
+++ b/modules/gui/qt/medialibrary/mlgenremodel.cpp
@@ -47,7 +47,7 @@ QVariant MLGenreModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || index.row() < 0)
return QVariant();
- const MLGenre* ml_genre = item(static_cast<unsigned int>(index.row()));
+ const MLGenre* ml_genre = item(index.row());
if (!ml_genre)
return QVariant();
diff --git a/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp b/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
index 4b95098c55..35e8a544b1 100644
--- a/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
+++ b/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
@@ -43,7 +43,7 @@ MLRecentsVideoModel::MLRecentsVideoModel( QObject* parent )
QVariant MLRecentsVideoModel::data( const QModelIndex& index , int role ) const
{
- const auto video = item( static_cast<unsigned int>( index.row() ) );
+ const auto video = item( index.row() );
if ( video == nullptr )
return {};
switch ( role )
diff --git a/modules/gui/qt/medialibrary/mlvideomodel.cpp b/modules/gui/qt/medialibrary/mlvideomodel.cpp
index fde7155b3b..2bd7e454c6 100644
--- a/modules/gui/qt/medialibrary/mlvideomodel.cpp
+++ b/modules/gui/qt/medialibrary/mlvideomodel.cpp
@@ -55,7 +55,7 @@ MLVideoModel::MLVideoModel(QObject* parent)
QVariant MLVideoModel::data(const QModelIndex& index, int role) const
{
- const auto video = item(static_cast<unsigned int>(index.row()));
+ const auto video = item(index.row());
if ( video == nullptr )
return {};
switch (role)
More information about the vlc-commits
mailing list