summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-08-17 17:26:04 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-08-21 20:23:40 +0000
commit51495e36da6e6d0e14e6116cd6be8927b3966b27 (patch)
tree6d70f91d6684ec56e5d001a79bd642699b7547d2
parent78c8cd581f70996d5ede328ca9416cdccab7f3cc (diff)
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. Task-number: QTBUG-103525 Change-Id: I2a9d3301118855fc95245a55bf64de6c46fa2f51 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> (cherry picked from commit a888239cf15fb18034122a06c687526c83dbdaa9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/io/qdebug.cpp8
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(&quote, 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);
}
}