summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <peter.penz19@gmail.com>2012-02-02 14:58:42 (GMT)
committerPeter Penz <peter.penz19@gmail.com>2012-02-02 15:02:31 (GMT)
commite196f065efeb911db931f549004daa8d9bbaa914 (patch)
treef49e2205288eda65210e96ae6cbae2cb49270463
parentd80f35e634aba07281f4339125e8d0a51cd07eda (diff)
Fix sorting issue when sorting by "size"
Root cause of the issue was an overflow in: result = a - b; where result is 'int' and a and b are 'KIO::filesize_t'. BUG: 293086 FIXED-IN: 4.8.1
-rw-r--r--dolphin/src/kitemviews/kfileitemmodel.cpp26
-rw-r--r--dolphin/src/kitemviews/kfileitemmodel.h6
2 files changed, 26 insertions, 6 deletions
diff --git a/dolphin/src/kitemviews/kfileitemmodel.cpp b/dolphin/src/kitemviews/kfileitemmodel.cpp
index d649546..95c960b 100644
--- a/dolphin/src/kitemviews/kfileitemmodel.cpp
+++ b/dolphin/src/kitemviews/kfileitemmodel.cpp
@@ -1301,21 +1301,24 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b) const
case SizeRole: {
if (itemA.isDir()) {
- Q_ASSERT(itemB.isDir()); // see "if (m_sortFoldersFirst || m_sortRole == SizeRole)" above
+ // See "if (m_sortFoldersFirst || m_sortRole == SizeRole)" in KFileItemModel::lessThan():
+ Q_ASSERT(itemB.isDir());
const QVariant valueA = a->values.value("size");
const QVariant valueB = b->values.value("size");
-
- if (valueA.isNull()) {
+ if (valueA.isNull() && valueB.isNull()) {
+ result = 0;
+ } else if (valueA.isNull()) {
result = -1;
} else if (valueB.isNull()) {
result = +1;
} else {
- result = valueA.value<KIO::filesize_t>() - valueB.value<KIO::filesize_t>();
+ result = fileSizeCompare(valueA.value<KIO::filesize_t>(), valueB.value<KIO::filesize_t>());
}
} else {
- Q_ASSERT(!itemB.isDir()); // see "if (m_sortFoldersFirst || m_sortRole == SizeRole)" above
- result = itemA.size() - itemB.size();
+ // See "if (m_sortFoldersFirst || m_sortRole == SizeRole)" in KFileItemModel::lessThan():
+ Q_ASSERT(!itemB.isDir());
+ result = fileSizeCompare(itemA.size(), itemB.size());
}
break;
}
@@ -1940,4 +1943,15 @@ KFileItemList KFileItemModel::childItems(const KFileItem& item) const
return items;
}
+int KFileItemModel::fileSizeCompare(KIO::filesize_t a, KIO::filesize_t b)
+{
+ if (a > b) {
+ return +1;
+ } else if (a < b) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
#include "kfileitemmodel.moc"
diff --git a/dolphin/src/kitemviews/kfileitemmodel.h b/dolphin/src/kitemviews/kfileitemmodel.h
index ff816c8..d819c37 100644
--- a/dolphin/src/kitemviews/kfileitemmodel.h
+++ b/dolphin/src/kitemviews/kfileitemmodel.h
@@ -330,6 +330,12 @@ private:
*/
KFileItemList childItems(const KFileItem& item) const;
+ /**
+ * Helper method for sortRoleCompare().
+ * @return 0 if both sizes are equal, +1 if a > b and -1 if a < b.
+ */
+ static int fileSizeCompare(KIO::filesize_t a, KIO::filesize_t b);
+
private:
QWeakPointer<KDirLister> m_dirLister;