[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kitemmodels] src: Properly sanitize input
From:       Aleix Pol <null () kde ! org>
Date:       2018-05-29 13:25:33
Message-ID: E1fNed3-0008Lm-HR () code ! kde ! org
[Download RAW message or body]

Git commit 958e7c9c56d9e767eb942582873f26f6e5b77353 by Aleix Pol.
Committed on 29/05/2018 at 13:24.
Pushed by apol into branch 'master'.

Properly sanitize input

Summary: Helps to use it together with ModelTest

Reviewers: #frameworks, broulik

Reviewed By: broulik

Subscribers: broulik, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D13043

M  +13   -3    src/kconcatenaterowsproxymodel.cpp

https://commits.kde.org/kitemmodels/958e7c9c56d9e767eb942582873f26f6e5b77353

diff --git a/src/kconcatenaterowsproxymodel.cpp b/src/kconcatenaterowsproxymodel.cpp
index ded00f8..2d745a1 100644
--- a/src/kconcatenaterowsproxymodel.cpp
+++ b/src/kconcatenaterowsproxymodel.cpp
@@ -67,6 +67,9 @@ KConcatenateRowsProxyModel::~KConcatenateRowsProxyModel()
 QModelIndex KConcatenateRowsProxyModel::mapFromSource(const QModelIndex \
&sourceIndex) const  {
     const QAbstractItemModel *sourceModel = sourceIndex.model();
+    if (!sourceModel) {
+        return {};
+    }
     int rowsPrior = d->computeRowsPrior(sourceModel);
     return createIndex(rowsPrior + sourceIndex.row(), sourceIndex.column());
 }
@@ -107,13 +110,16 @@ bool KConcatenateRowsProxyModel::setData(const QModelIndex \
&index, const QVarian  QMap<int, QVariant> KConcatenateRowsProxyModel::itemData(const \
QModelIndex &proxyIndex) const  {
     const QModelIndex sourceIndex = mapToSource(proxyIndex);
+    if (!sourceIndex.isValid()) {
+        return {};
+    }
     return sourceIndex.model()->itemData(sourceIndex);
 }
 
 Qt::ItemFlags KConcatenateRowsProxyModel::flags(const QModelIndex &index) const
 {
     const QModelIndex sourceIndex = mapToSource(index);
-    return sourceIndex.model()->flags(sourceIndex);
+    return sourceIndex.isValid() ? sourceIndex.model()->flags(sourceIndex) : \
Qt::ItemFlags();  }
 
 QVariant KConcatenateRowsProxyModel::headerData(int section, Qt::Orientation \
orientation, int role) const @@ -146,8 +152,12 @@ int \
KConcatenateRowsProxyModel::columnCount(const QModelIndex &parent) const  
 QModelIndex KConcatenateRowsProxyModel::index(int row, int column, const QModelIndex \
&parent) const  {
-    Q_ASSERT(row >= 0);
-    Q_ASSERT(column >= 0);
+    if(row < 0) {
+        return {};
+    }
+    if(column < 0) {
+        return {};
+    }
     int sourceRow;
     QAbstractItemModel *sourceModel = d->sourceModelForRow(row, &sourceRow);
     if (!sourceModel) {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic