diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-08-17 17:26:04 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-08-21 08:28:51 +0200 |
commit | a888239cf15fb18034122a06c687526c83dbdaa9 (patch) | |
tree | fb73c5acfa761ee7f6bc5880d2f413833f94daa1 /src | |
parent | bcc32bc1128544cceb41d337ee16bc36c3eb188f (diff) | |
download | qtbase-a888239cf15fb18034122a06c687526c83dbdaa9.tar.gz |
QDebug: port putEscapedString() from int to size_t
All callers of the function pass size_t values, so remove the
impedance mismatch and preserve the value.
Adjust local variable runLength to qsizetype, because with this change
the int variable may now overflow, which would cause infinite looping.
Adjust callers to not perform narrowing conversions.
Pick-to: 6.4 6.3 6.2
Task-number: QTBUG-103525
Change-Id: I2a9d3301118855fc95245a55bf64de6c46fa2f51
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/io/qdebug.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 54b2d605e6..1c6ffa57c3 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -203,7 +203,7 @@ static inline bool isPrintable(uchar c) { return c >= ' ' && c < 0x7f; } template <typename Char> -static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, int length, bool isUnicode = true) +static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, size_t length, bool isUnicode = true) { QChar quote(u'"'); d->write("e, 1); @@ -223,7 +223,7 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, in if (sizeof(Char) == sizeof(QChar)) { // Surrogate characters are category Cs (Other_Surrogate), so isPrintable = false for them - int runLength = 0; + qsizetype runLength = 0; while (p + runLength != end && isPrintable(p[runLength]) && p[runLength] != '\\' && p[runLength] != '"') ++runLength; @@ -325,7 +325,7 @@ void QDebug::putString(const QChar *begin, size_t length) // we'll reset the QTextStream formatting mechanisms, so save the state QDebugStateSaver saver(*this); stream->ts.d_ptr->params.reset(); - putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const ushort *>(begin), int(length)); + putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const ushort *>(begin), length); } } @@ -345,7 +345,7 @@ void QDebug::putByteArray(const char *begin, size_t length, Latin1Content conten QDebugStateSaver saver(*this); stream->ts.d_ptr->params.reset(); putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const uchar *>(begin), - int(length), content == ContainsLatin1); + length, content == ContainsLatin1); } } |