diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2025-07-10 12:52:57 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2025-07-14 22:25:35 +0000 |
| commit | b9f6a1b113d8f26210da5c3194f0f790883761fe (patch) | |
| tree | 9d081c5ce065e8a43d37b1396e96f62a346fb294 /src/corelib/io/qdebug.cpp | |
| parent | 8e398cec88f6019edc83e52cab64e3ef52bef173 (diff) | |
QTextStream: use write(QChar) more
Replace write(&ch, 1) calls with write(ch) ones.
The QChar overload, added in 31c6d9f04ba80e6776ae01cb0588e6bd228f7184,
is safer, because it has less preconditions. With QTextStream being
security-critical, we should target to use safer functions to do the
same work, even if it introduces a bit of git history churn.
The call from a different TU (qdebug.cpp) means we need to remove the
lying inline keywords from both declaration and definition of
write(QChar), because GCC -Werrors on them.
As a drive-by, remove a use of QLatin1Char, in preparation of moving
from QChar to char16_t, eventually.
Pick-to: 6.10 6.9 6.8
Change-Id: I97b4c8c68a4ee0d4b821c4d2ec4a9dd6f44dceb0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qdebug.cpp')
| -rw-r--r-- | src/corelib/io/qdebug.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 70a688e40ff..5d6b5e06be6 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -200,7 +200,7 @@ template <typename Char> static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, size_t length, bool isUnicode = true) { QChar quote(u'"'); - d->write("e, 1); + d->write(quote); bool lastWasHexEscape = false; const Char *end = begin + length; @@ -227,8 +227,7 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, si continue; } } else if (isPrintable(*p) && *p != '\\' && *p != '"') { - QChar c = QLatin1Char(*p); - d->write(&c, 1); + d->write(char16_t{uchar(*p)}); continue; } @@ -302,7 +301,7 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, si d->write(reinterpret_cast<QChar *>(buf), buflen); } - d->write("e, 1); + d->write(quote); } /*! |
