QRegularExpression: don't detach() a pattern QStringLiteral

... just to pass it to pcre2_compile_16().

The QString::utf16() function guarantees a NUL-terminated result, so
it detach()es from QStringLiteral (Qt 6) and/or QString::fromRawData()
(Qt 5 + 6).

This user doesn't require the NUL-termination, though, since
pcre2_compile_16() takes an explicit length, so the detach() is
completely unneccesary, yet common, since regex pattern strings are
often QStringLiteral()s.

Task-number: QTBUG-98763
Change-Id: I1d08ae1a1ec4281ff44a68c5ba5c56584b71d24e
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
Marc Mutz 2021-11-29 17:22:04 +01:00
parent 4c930e9d13
commit be84b033dc

View File

@ -910,7 +910,7 @@ void QRegularExpressionPrivate::compilePattern()
options |= PCRE2_UTF;
PCRE2_SIZE patternErrorOffset;
compiledPattern = pcre2_compile_16(reinterpret_cast<PCRE2_SPTR16>(pattern.utf16()),
compiledPattern = pcre2_compile_16(reinterpret_cast<PCRE2_SPTR16>(pattern.constData()),
pattern.length(),
options,
&errorCode,