diff options
author | Marc Mutz <[email protected]> | 2024-07-29 21:38:26 +0200 |
---|---|---|
committer | Marc Mutz <[email protected]> | 2024-07-31 22:07:18 +0200 |
commit | d042c14c9940c6aabaa5b39d3061c0f9e50fff06 (patch) | |
tree | fd6e1332a4f462d2f2bd3d1c733b78199d1fb184 | |
parent | fd8cec34965afc8ca6d7f5e844e8aab44e182c90 (diff) |
QtTest: port approx_wide_len() from std::clamp() to qt_saturate()
The patch that originally added the function used std::clamp() because
qt_saturate() wasn't available in all the branches to which the patch
was backported. This patch modernizes the code for newer branches.
Pick-to: 6.8 6.7 6.5
Change-Id: I1b764d303e00ec04858643efed3dcc71f2c7ce4c
Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r-- | src/testlib/qtestresult.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp index 6714d38ddf8..b4e50499267 100644 --- a/src/testlib/qtestresult.cpp +++ b/src/testlib/qtestresult.cpp @@ -12,7 +12,8 @@ #include <QtTest/qtestassert.h> #include <QtTest/qtesteventloop.h> -#include <algorithm> +#include <QtCore/private/qnumeric_p.h> + #include <climits> #include <cwchar> @@ -334,11 +335,10 @@ static int approx_wide_len(const char *s) std::mbstate_t state = {}; // QNX might stop at max when dst == nullptr, so pass INT_MAX, // being the largest value this function will return: - constexpr size_t max = INT_MAX; - auto r = std::mbsrtowcs(nullptr, &s, max, &state); + auto r = std::mbsrtowcs(nullptr, &s, INT_MAX, &state); if (r == size_t(-1)) // encoding error, fall back to strlen() r = strlen(s); // `s` was not advanced since `dst == nullptr` - return int(std::clamp(r, size_t(0), max)); + return qt_saturate<int>(r); } // Overload to format failures for "const char *" - no need to strdup(). |