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. Change-Id: I725eb9e4a9304d2edcd0776e756e6a67e224c1a7 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit 62aec32dfa27867e693f13976c4e3a3df11805d1) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
9e92dd2034
commit
d4f4bc6c6e
@ -807,8 +807,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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user