summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-12-15 09:07:17 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-12-15 18:42:25 +0000
commit89d6f66edb03b5b430b7b266d705a30a490c86e3 (patch)
tree09478ac27bd72d552487a5678552bb9a6ac6d0bd /src/corelib/global
parent7d2ae0bf0d9cb39ba9f0c1b146c3b854cebb3710 (diff)
QLogging: fix potential missing NUL-terminator when calling OutputDebugString
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. Change-Id: Ie42a6000c75c6a55d629621d89e0cf498b174d29 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 7ef614017091d7b56ac905c43da035259583c077)
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qlogging.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 9708ab75da..877831cc8b 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -1669,7 +1669,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 int maxOutputStringLength = 32766;
static QBasicMutex m;
@@ -1681,7 +1681,7 @@ static void win_outputDebugString_helper(QStringView message)
wchar_t *messagePart = new wchar_t[maxOutputStringLength + 1];
for (int i = 0; i < message.length(); i += maxOutputStringLength ) {
const int length = std::min(message.length() - i, maxOutputStringLength );
- const int len = message.mid(i, length).toWCharArray(messagePart);
+ const int len = QStringView{message}.mid(i, length).toWCharArray(messagePart);
Q_ASSERT(len == length);
messagePart[len] = 0;
OutputDebugString(messagePart);