From e7aa8aa118ba0eef688422328117bd466f548aee Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 29 Jul 2024 21:38:26 +0200 Subject: [PATCH] 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.7 6.5 Change-Id: I1b764d303e00ec04858643efed3dcc71f2c7ce4c Reviewed-by: Thiago Macieira (cherry picked from commit d042c14c9940c6aabaa5b39d3061c0f9e50fff06) Reviewed-by: Qt Cherry-pick Bot --- src/testlib/qtestresult.cpp | 8 ++++---- 1 file 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 #include -#include +#include + #include #include @@ -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(r); } // Overload to format failures for "const char *" - no need to strdup().