From be84b033dca2bb347c4c6c4d7e487d2cb0a2502b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 29 Nov 2021 17:22:04 +0100 Subject: 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 --- src/corelib/text/qregularexpression.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index 4fe86e9d6a..1db27fc4e4 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -910,7 +910,7 @@ void QRegularExpressionPrivate::compilePattern() options |= PCRE2_UTF; PCRE2_SIZE patternErrorOffset; - compiledPattern = pcre2_compile_16(reinterpret_cast(pattern.utf16()), + compiledPattern = pcre2_compile_16(reinterpret_cast(pattern.constData()), pattern.length(), options, &errorCode, -- cgit v1.2.3