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>
This commit is contained in:
Marc Mutz 2023-09-28 08:15:05 +02:00 committed by Ivan Solovev
parent 94df3f8d6b
commit 49f9271360

View File

@ -19,6 +19,8 @@
#include <qdatetime.h>
#include <qloggingcategory.h>
#include <functional>
#include <limits.h>
QT_BEGIN_NAMESPACE
@ -402,7 +404,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);
}
/*!