From a888239cf15fb18034122a06c687526c83dbdaa9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 17 Aug 2022 17:26:04 +0200 Subject: [PATCH] QDebug: port putEscapedString() from int to size_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/io/qdebug.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 54b2d605e69..1c6ffa57c3c 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 -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(begin), int(length)); + putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast(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(begin), - int(length), content == ContainsLatin1); + length, content == ContainsLatin1); } }