diff options
author | MÃ¥rten Nordheim <marten.nordheim@qt.io> | 2022-06-08 14:11:06 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-06-28 00:39:47 +0000 |
commit | 810c41093f9e1df334f6e06316388d06f18d1942 (patch) | |
tree | edba1d2a5fad6aa9409464b0fa6f0b5339af94c3 | |
parent | b6e4456f1f9b1cc9bab1a1d3ddbe0892668e548e (diff) |
QTest: switch some text-conversion functions to use qsizetype
To avoid potential narrowing.
Task-number: QTBUG-104125
Change-Id: I37bfc5c49e7c919f5204a76a905758a92527d864
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 44927b801ab8afac901132f9505a42b41821cb55)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/testlib/qtestcase.cpp | 18 | ||||
-rw-r--r-- | src/testlib/qtestcase.h | 4 |
2 files changed, 10 insertions, 12 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index f6c9a9f87e..6b5584366d 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1460,8 +1460,6 @@ char *formatString(const char *prefix, const char *suffix, size_t numArguments, } /*! - \fn char* QTest::toHexRepresentation(const char *ba, int length) - Returns a pointer to a string that is the string \a ba represented as a space-separated sequence of hex characters. If the input is considered too long, it is truncated. A trucation is indicated in @@ -1471,7 +1469,7 @@ char *formatString(const char *prefix, const char *suffix, size_t numArguments, \a length is the length of the string \a ba. */ -char *toHexRepresentation(const char *ba, int length) +char *toHexRepresentation(const char *ba, qsizetype length) { if (length == 0) return qstrdup(""); @@ -1483,12 +1481,12 @@ char *toHexRepresentation(const char *ba, int length) * maxLen can't be for example 200 because Qt Test is sprinkled with fixed * size char arrays. * */ - const int maxLen = 50; - const int len = qMin(maxLen, length); + const qsizetype maxLen = 50; + const qsizetype len = qMin(maxLen, length); char *result = nullptr; if (length > maxLen) { - const int size = len * 3 + 4; + const qsizetype size = len * 3 + 4; result = new char[size]; char *const forElipsis = result + size - 5; @@ -1499,13 +1497,13 @@ char *toHexRepresentation(const char *ba, int length) result[size - 1] = '\0'; } else { - const int size = len * 3; + const qsizetype size = len * 3; result = new char[size]; result[size - 1] = '\0'; } - int i = 0; - int o = 0; + qsizetype i = 0; + qsizetype o = 0; while (true) { const char at = ba[i]; @@ -1530,7 +1528,7 @@ char *toHexRepresentation(const char *ba, int length) Returns the same QByteArray but with only the ASCII characters still shown; everything else is replaced with \c {\xHH}. */ -char *toPrettyCString(const char *p, int length) +char *toPrettyCString(const char *p, qsizetype length) { bool trimmed = false; auto buffer = std::make_unique<char[]>(256); diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index ab64d712f9..7db64af8ab 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -346,8 +346,8 @@ namespace QTest template <class... Types> inline char *toString(const std::tuple<Types...> &tuple); - Q_TESTLIB_EXPORT char *toHexRepresentation(const char *ba, int length); - Q_TESTLIB_EXPORT char *toPrettyCString(const char *unicode, int length); + Q_TESTLIB_EXPORT char *toHexRepresentation(const char *ba, qsizetype length); + Q_TESTLIB_EXPORT char *toPrettyCString(const char *unicode, qsizetype length); Q_TESTLIB_EXPORT char *toPrettyUnicode(QStringView string); Q_TESTLIB_EXPORT char *toString(const char *); Q_TESTLIB_EXPORT char *toString(const volatile void *); |