From bcc32bc1128544cceb41d337ee16bc36c3eb188f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 17 Aug 2022 16:58:09 +0200 Subject: Port QtDebugUtils::toPrintable() to qint64/qsizetype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some callers pass qint64 arguments to the len parameter, so take the size as qint64, not qsizetype, to avoid silent truncation. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-103525 Change-Id: I4bc5673297f24aea0cfc9d20887dc8a877743214 Reviewed-by: MÃ¥rten Nordheim --- src/corelib/io/qdebug.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/corelib/io/qdebug.cpp') diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 524a04456a7..54b2d605e69 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -24,15 +24,16 @@ using QtMiscUtils::fromHex; /* Returns a human readable representation of the first \a maxSize - characters in \a data. + characters in \a data. The size, \a len, is a 64-bit quantity to + avoid truncation due to implicit conversions in callers. */ -QByteArray QtDebugUtils::toPrintable(const char *data, int len, int maxSize) +QByteArray QtDebugUtils::toPrintable(const char *data, qint64 len, qsizetype maxSize) { if (!data) return "(null)"; QByteArray out; - for (int i = 0; i < qMin(len, maxSize); ++i) { + for (qsizetype i = 0; i < qMin(len, maxSize); ++i) { char c = data[i]; if (isprint(c)) { out += c; -- cgit v1.2.3