From a228f1f399bc25dcb9e5caafafd356a9df01c7af Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 22 Jul 2024 14:59:18 +0200 Subject: [PATCH] ipctestcommon.h: port away from qsnprintf() Use std::snprintf() instead. Also use qToUnderlying() instead of explicit cast to unsigned (so the compiler warns us should the underlying type of he QNativeIpcKey::Type enum ever change) and applyRAII to temporary toString() results. Amends 32a06e983073080d939b4742996a3dc9cd75bb83. Pick-to: 6.7 Change-Id: I4dd00672382d377285d722a47d998bdf12422eb4 Reviewed-by: Ivan Solovev (cherry picked from commit ce7b8fc91d82402cbed230e83c00cab3a54f9916) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/corelib/ipc/ipctestcommon.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/auto/corelib/ipc/ipctestcommon.h b/tests/auto/corelib/ipc/ipctestcommon.h index 2347031ad45..4ea9d4eeab6 100644 --- a/tests/auto/corelib/ipc/ipctestcommon.h +++ b/tests/auto/corelib/ipc/ipctestcommon.h @@ -5,6 +5,9 @@ #include #include +#include +#include + namespace IpcTestCommon { static QList supportedKeyTypes; @@ -64,7 +67,7 @@ template<> inline char *toString(const QNativeIpcKey::Type &type) return qstrdup("Invalid"); char buf[32]; - qsnprintf(buf, sizeof(buf), "%u", unsigned(type)); + std::snprintf(buf, sizeof(buf), "%u", qToUnderlying(type)); return qstrdup(buf); } @@ -73,12 +76,11 @@ template<> inline char *toString(const QNativeIpcKey &key) if (!key.isValid()) return qstrdup(""); - const char *type = toString(key.type()); - const char *text = toString(key.nativeKey()); + using UP = std::unique_ptr; + const auto type = UP{toString(key.type())}; + const auto text = UP{toString(key.nativeKey())}; char buf[256]; - qsnprintf(buf, sizeof(buf), "QNativeIpcKey(%s, %s)", text, type); - delete[] type; - delete[] text; + std::snprintf(buf, sizeof(buf), "QNativeIpcKey(%s, %s)", text.get(), type.get()); return qstrdup(buf); } } // namespace QTest