Replace manual index bound checks with calls to checkIndex

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2022-10-01 16:49:28 +02:00
parent fb4bb95b91
commit 639fb21a13
No known key found for this signature in database
GPG key ID: C839200C384636B0
2 changed files with 3 additions and 7 deletions

View 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());

View 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;