From 7ef614017091d7b56ac905c43da035259583c077 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 15 Dec 2021 09:07:17 +0100 Subject: QLogging: fix potential missing NUL-terminator when calling OutputDebugString MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The string returned from QStringView::utf16() is, in general, not NUL-terminated, as OutputDebugString() requires. Though we only ever call win_outputDebugString_helper() with an actual QString, it's not 100% clear said QString doesn't originate from, say, a QStringLiteral, in which case QString::utf16() would have to (an does) detach() to ensure the NUL-termination. So, take by const QString&, but use QStringView::mid() to avoid copying the substring content twice. Amends a049325cc708b483ed1aadc6589419f4d74b19f3. Pick-to: 6.3 6.2 5.15 Change-Id: Ie42a6000c75c6a55d629621d89e0cf498b174d29 Reviewed-by: Qt CI Bot Reviewed-by: MÃ¥rten Nordheim --- src/corelib/global/qlogging.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/global/qlogging.cpp') diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index f2d4a50a2c..6e4da27d5e 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1671,7 +1671,7 @@ static bool android_default_message_handler(QtMsgType type, #endif //Q_OS_ANDROID #ifdef Q_OS_WIN -static void win_outputDebugString_helper(QStringView message) +static void win_outputDebugString_helper(const QString &message) { const qsizetype maxOutputStringLength = 32766; static QBasicMutex m; @@ -1683,7 +1683,7 @@ static void win_outputDebugString_helper(QStringView message) wchar_t *messagePart = new wchar_t[maxOutputStringLength + 1]; for (qsizetype i = 0; i < message.length(); i += maxOutputStringLength) { const qsizetype length = qMin(message.length() - i, maxOutputStringLength); - const qsizetype len = message.mid(i, length).toWCharArray(messagePart); + const qsizetype len = QStringView{message}.mid(i, length).toWCharArray(messagePart); Q_ASSERT(len == length); messagePart[len] = 0; OutputDebugString(messagePart); -- cgit v1.2.3