summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-08-11 15:11:52 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-08-12 18:32:29 +0000
commit62aec32dfa27867e693f13976c4e3a3df11805d1 (patch)
tree9ebabb7d43dd030ae85bfd3c9cac17dd18fca210 /src/corelib/text/qlocale.cpp
parent6234182d82b5f645a61c89219d71ab6a4ac03609 (diff)
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 <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/text/qlocale.cpp')
-rw-r--r--src/corelib/text/qlocale.cpp4
1 files changed, 2 insertions, 2 deletions
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;
}