From f6b96bc34749e4478e75c081bbd0af406cd737b5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 8 May 2020 22:46:44 +0200 Subject: QString: fix UB in replace() Comparing with <, >, <= or >= such pointers as are not pointing into the same array is UB. A clever compiler could look at the code, determine that the only valid execution is for it to return true, and just always take the copy. While that would be benign, it's not guaranteed that this would be the outcome (it's UB, after all), and, of course, we don't want to take the performance hit if we don't need it. Pick-to: 5.15 Change-Id: I48cda232ff10a3c9fd4babcd7e7103a3aed126e8 Reviewed-by: Ville Voutilainen --- src/corelib/text/qstring.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index fea5fb00df..49ddb9279b 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -3038,7 +3038,8 @@ QChar *textCopy(const QChar *start, int len) bool pointsIntoRange(const QChar *ptr, const ushort *base, int len) { const QChar *const start = reinterpret_cast(base); - return start <= ptr && ptr < start + len; + const std::less less; + return !less(ptr, start) && less(ptr, start + len); } } // end namespace -- cgit v1.2.3