[vlmc-devel] MediaLibraryModel: Fail early in case of invalid model index

Hugo Beauzée-Luyssen git at videolan.org
Tue Jul 12 00:26:42 CEST 2016


vlmc | branch: medialibrary | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Mon Jul 11 22:00:58 2016 +0200| [f00637564e6380961145a40000e972fe9722c472] | committer: Hugo Beauzée-Luyssen

MediaLibraryModel: Fail early in case of invalid model index

> https://code.videolan.org/videolan/vlmc/commit/f00637564e6380961145a40000e972fe9722c472
---

 src/Library/MediaLibraryModel.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/Library/MediaLibraryModel.cpp b/src/Library/MediaLibraryModel.cpp
index 8b86cc1..7a3ebed 100644
--- a/src/Library/MediaLibraryModel.cpp
+++ b/src/Library/MediaLibraryModel.cpp
@@ -81,13 +81,12 @@ int MediaLibraryModel::rowCount( const QModelIndex& index ) const
 
 QVariant MediaLibraryModel::data( const QModelIndex &index, int role ) const
 {
+    if ( !index.isValid() || index.row() < 0 || index.row() >= m_rowCount )
+        return QVariant();
+
     medialibrary::MediaPtr m;
     {
         std::lock_guard<std::mutex> lock( m_mediaMutex );
-
-        if ( !index.isValid() || index.row() < 0 ||
-             static_cast<size_t>( index.row() ) >= m_media.size() )
-            return QVariant();
         m = m_media.at( static_cast<size_t>( index.row() ) );
     }
 



More information about the Vlmc-devel mailing list