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>
This commit is contained in:
parent
9afd95eb68
commit
0872212812
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user