diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-08-17 16:58:09 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-08-21 20:23:33 +0000 |
commit | 78c8cd581f70996d5ede328ca9416cdccab7f3cc (patch) | |
tree | 9a1dcf9bb56f3c62c4fd7cd1253716b74083c540 /src | |
parent | c99bee92a096e879bd7968412418419278800423 (diff) |
Port QtDebugUtils::toPrintable() to qint64/qsizetype
Some callers pass qint64 arguments to the len parameter, so take the
size as qint64, not qsizetype, to avoid silent truncation.
Task-number: QTBUG-103525
Change-Id: I4bc5673297f24aea0cfc9d20887dc8a877743214
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit bcc32bc1128544cceb41d337ee16bc36c3eb188f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/io/qdebug.cpp | 7 | ||||
-rw-r--r-- | 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 524a04456a..54b2d605e6 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 1dead0f47d..810fc3b4b6 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. |