From 50b62d3b19bf8f2d9de9bb7f84b3e5930ff0ee4b Mon Sep 17 00:00:00 2001 From: Marc Mutz <marc.mutz@qt.io> Date: Thu, 28 Sep 2023 08:15:05 +0200 Subject: [PATCH 126/147] QPersistentModelIndex: fix UB (op< on unrelated pointers) Pointers can only be legitimately compared with less-than (<) if they point into the same array (or one past the end). This is decidedly not the case for heap-allocated objects like QPersistentModelIndexPrivates, so doing it is UB. Fix by using std::less, which is guaranteed to be a total order, even for unrelated pointer values. Pick-to: 6.6 6.5 6.2 5.15 Change-Id: If04341b4b55784e7732782f3ae829f53b0ceab9c Reviewed-by: David Faure <david.faure@kdab.com> (cherry picked from commit 49f9271360e0ef4e624212e442dfcd7765571d60) --- src/corelib/itemmodels/qabstractitemmodel.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 997a634e76..1c1ca7394d 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -52,6 +52,8 @@ #include <qdatetime.h> #include <qloggingcategory.h> +#include <functional> + #include <limits.h> QT_BEGIN_NAMESPACE @@ -213,7 +215,7 @@ bool QPersistentModelIndex::operator<(const QPersistentModelIndex &other) const if (d && other.d) return d->index < other.d->index; - return d < other.d; + return std::less<>{}(d, other.d); } /*! -- 2.40.1