Replace manual index bound checks with calls to checkIndex
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Sat, 1 Oct 2022 14:49:28 +0000 (16:49 +0200)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 31 Oct 2022 17:06:08 +0000 (18:06 +0100)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/filedetails/shareemodel.cpp
src/gui/filedetails/sharemodel.cpp

index 6f4fd97a6ac8aef1e8cdc77666e7fe2cdfad3768..85ae47c65f0353c04642e8f6a8b6b721af783eb0 100644 (file)
@@ -54,9 +54,7 @@ QHash<int, QByteArray> ShareeModel::roleNames() const
 
 QVariant ShareeModel::data(const QModelIndex &index, const int role) const
 {
-    if (index.row() < 0 || index.row() > _sharees.size()) {
-        return {};
-    }
+    Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid | QAbstractItemModel::CheckIndexOption::ParentIsInvalid));
 
     const auto sharee = _sharees.at(index.row());
 
index 9814e3c23d754882c46a0f4798cbba1e6bab1f37..c1e38e45bf45f3b0a8ad4479c105997e38edd1e0 100644 (file)
@@ -85,9 +85,7 @@ QHash<int, QByteArray> ShareModel::roleNames() const
 
 QVariant ShareModel::data(const QModelIndex &index, const int role) const
 {
-    if (!index.isValid()) {
-        return {};
-    }
+    Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid | QAbstractItemModel::CheckIndexOption::ParentIsInvalid));
 
     const auto share = _shares.at(index.row());
 
@@ -419,7 +417,7 @@ void ShareModel::slotRemoveShareWithId(const QString &shareId)
     _shareIdRecentlySetPasswords.remove(shareId);
     const auto shareIndex = _shareIdIndexHash.take(shareId);
 
-    if (!shareIndex.isValid()) {
+    if (!checkIndex(shareIndex, QAbstractItemModel::CheckIndexOption::IndexIsValid | QAbstractItemModel::CheckIndexOption::ParentIsInvalid)) {
         qCWarning(lcShareModel) << "Won't remove share with id:" << shareId
                                 << ", invalid share index: " << shareIndex;
         return;