From bcc32bc1128544cceb41d337ee16bc36c3eb188f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 17 Aug 2022 16:58:09 +0200 Subject: [PATCH] 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 ++++--- src/corelib/io/qdebug_p.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) 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; diff --git a/src/corelib/io/qdebug_p.h b/src/corelib/io/qdebug_p.h index 1dead0f47da..810fc3b4b65 100644 --- a/src/corelib/io/qdebug_p.h +++ b/src/corelib/io/qdebug_p.h @@ -25,7 +25,7 @@ QT_BEGIN_NAMESPACE namespace QtDebugUtils { -Q_CORE_EXPORT QByteArray toPrintable(const char *data, int len, int maxSize); +Q_CORE_EXPORT QByteArray toPrintable(const char *data, qint64 len, qsizetype maxSize); // inline helpers for formatting basic classes.