From 0872212812374b5d5db2a8c7dc530bc3515552fa Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 13 Feb 2024 16:29:08 +0100 Subject: [PATCH] QMinimalFlatSet: fix UB (using op< on pointers) when is_pointer 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 --- src/corelib/tools/qminimalflatset_p.h | 7 +++++-- 1 file 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 // for std::lower_bound +#include // 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{}; + + 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