From 075fa6203856bdf9f58e737ee2f5d2a843a85cad Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 31 Jul 2019 16:15:31 +0300 Subject: AVFCameraUtility: fix UB (std::sort with unfit predicate) ResolutionPredicate defines an order on the resolutions (expressed as QSize) of AVCaptureDeviceFormats, from smallest (width as primary, height as secondary sort key) to largest, as the lexicographical less-than of width and height. A a lexicographical order over Strict Weak Orders is a Strict Weak Order of the product type. So far, so good. The logical negation of a Stict Weak Order is, however, not a Strict Weak Order (not-less-than is greater-or-equal, not greater-than), so it cannot be used as the predicate in std::sort. Rewrite the ResolutionPredicate as an adapter that can be used with std::less _or_ std::greater (or even std::equal_to), piggy-backing on std::tuple to implement the lexicographical sort for us, then replace not2(ResolutionPredicate) with ResolutionPredicate. Rename the predicate to something more apt. This also solves the use of deprecated (and in C++20, removed) std::not2. Change-Id: I6f81b149e53a5b4299b188bf3ce996f638bf3334 Reviewed-by: Timur Pocheptsov --- src/plugins/avfoundation/camera/avfcamerautility.mm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/avfoundation/camera/avfcamerautility.mm b/src/plugins/avfoundation/camera/avfcamerautility.mm index 8a2254c2e..b2460e748 100644 --- a/src/plugins/avfoundation/camera/avfcamerautility.mm +++ b/src/plugins/avfoundation/camera/avfcamerautility.mm @@ -47,6 +47,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -85,14 +86,18 @@ inline bool qt_area_sane(const QSize &size) && std::numeric_limits::max() / size.width() >= size.height(); } -struct ResolutionPredicate : std::binary_function +template