QStringRef: handle integer overflow in right(), mid(), and trimmed()
The class stores the position (in the referenced string) and the length
of the referenced chunk as int.
This means that neither of them can exceed INT_MAX, but they can still
technically reference a portion of data with indices past INT_MAX.
For example, with position() == INT_MAX / 2, and size() == INT_MAX.
With such a setup, methods like right(n) or mid(pos, n) can overflow
when calculating the position() of the returned QStringRef. The same
can happen for trimmed(), if it has too many whitespaces in front.
For right() and mid(), handle these cases gracefully, and return
either a reference to the entire string, or a null QStringRef. That is
in line with the docs for these methods, which already handle invalid
input similarly.
For trimmed(), simply document the limitation, and add Q_PRE().
Add tests for right() and mid(), but do not for trimmed(), because
Q_PRE() is not testable, yet.
Task-number: QTBUG-149430
Pick-to: 6.12 6.11 6.8
Change-Id: I5cd41a9be7359313d969ba017d49111432884c9d
Reviewed-by: Marc Mutz <marc.mutz@qt.io>