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.

Pick-to: 6.4 6.3 6.2
Task-number: QTBUG-103525
Change-Id: I4bc5673297f24aea0cfc9d20887dc8a877743214
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2022-08-17 16:58:09 +02:00
parent 52c5f28695
commit bcc32bc112
2 changed files with 5 additions and 4 deletions

View File

@ -24,15 +24,16 @@ using QtMiscUtils::fromHex;
/* /*
Returns a human readable representation of the first \a maxSize 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) if (!data)
return "(null)"; return "(null)";
QByteArray out; QByteArray out;
for (int i = 0; i < qMin(len, maxSize); ++i) { for (qsizetype i = 0; i < qMin(len, maxSize); ++i) {
char c = data[i]; char c = data[i];
if (isprint(c)) { if (isprint(c)) {
out += c; out += c;

View File

@ -25,7 +25,7 @@ QT_BEGIN_NAMESPACE
namespace QtDebugUtils { 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. // inline helpers for formatting basic classes.