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>
This commit is contained in:
Marc Mutz 2022-08-11 15:11:52 +02:00
parent 6234182d82
commit 62aec32dfa

View File

@ -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;
}