summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-02-13 16:29:08 +0100
committerMarc Mutz <marc.mutz@qt.io>2024-02-25 12:55:19 +0100
commit0872212812374b5d5db2a8c7dc530bc3515552fa (patch)
treee20d8695950fdca88a1503c3712ed01abee00190 /src/corelib/tools
parent9afd95eb689b48293dde924fa29fc65ffa058ac6 (diff)
QMinimalFlatSet: fix UB (using op< on pointers) when is_pointer<value_type>
Using operator< on pointers that are not part of the same array is UB. We need to use std::less to get a total order, so do that. The QMinimalFlatSet copy in QtDeclarative is not affected, because it's only ever instantiated with value_type int. Change-Id: Ic8cd4852505f3d3ab57039ce26064ed47cac0deb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qminimalflatset_p.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/corelib/tools/qminimalflatset_p.h b/src/corelib/tools/qminimalflatset_p.h
index 0798aa7a98..c6466cf361 100644
--- a/src/corelib/tools/qminimalflatset_p.h
+++ b/src/corelib/tools/qminimalflatset_p.h
@@ -29,6 +29,7 @@
#endif
#include <algorithm> // for std::lower_bound
+#include <functional> // for std::less
QT_BEGIN_NAMESPACE
@@ -120,8 +121,10 @@ private:
bool exists;
};
- const auto it = std::lower_bound(c.cbegin(), c.cend(), v);
- return R{it, it != c.cend() && !(v < *it)};
+ auto cmp = std::less<value_type>{};
+
+ const auto it = std::lower_bound(c.cbegin(), c.cend(), v, cmp);
+ return R{it, it != c.cend() && !cmp(v, *it)};
}
#ifdef QMINIMAL_FLAT_SET_DEBUG