From 62aec32dfa27867e693f13976c4e3a3df11805d1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 11 Aug 2022 15:11:52 +0200 Subject: QLocale: fix UB in defaultIndex() (using < on unrelated pointers) It's undefined behavior to compare pointers with <, >, <=, >=, unless they point into the same subobject (or one past the last element, for arrays). The Q_ASSERT() should detect UB. For that, it mustn't cause UB itself. Fix by using q_points_into_range(), which uses std::less, which is guaranteed to define a total order on pointer values. Pick-to: 6.4 6.3 6.2 Change-Id: I725eb9e4a9304d2edcd0776e756e6a67e224c1a7 Reviewed-by: Edward Welbourne --- src/corelib/text/qlocale.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 82e15186cb..ebf2770b56 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -806,8 +806,8 @@ static uint defaultIndex() } #endif - Q_ASSERT(data >= locale_data); - Q_ASSERT(data < locale_data + std::size(locale_data)); + using QtPrivate::q_points_into_range; + Q_ASSERT(q_points_into_range(data, locale_data, std::end(locale_data))); return data - locale_data; } -- cgit v1.2.3