From 57ad4caa7b7094d6fac07e14def8cbd76753381d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 22 Jul 2024 15:30:37 +0200 Subject: [PATCH] tst_QDeadlineTimer: fix format-string in toString() implementation The second value (like the first) has type qint64 (aka long long), so %d is wrong; need to use %lld instead. Found while porting to std::snprintf() (qsnprintf() never actually got the __attribute__((printf)), so compilers didn't warn). Drive-by replace qAbs() with std::abs(). Amends 13c3558fe9967391374555cfeb3209b961a86084. Pick-to: 6.7 6.5 Change-Id: I9082a1aceefe8a5b04ad0d5725ab666e23483b29 Reviewed-by: Thiago Macieira Reviewed-by: Ivan Solovev (cherry picked from commit 61e4be2b62f9b6556a145f226850bf5e62d53e9d) Reviewed-by: Qt Cherry-pick Bot --- .../kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp index 79416faaf98..8b4cfeb4faf 100644 --- a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp +++ b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp @@ -10,6 +10,9 @@ #include #include +#include +#include + #include static const int minResolution = 400; // the minimum resolution for the tests @@ -23,9 +26,10 @@ template<> char *toString(const QDeadlineTimer &dt) qint64 deadline = dt.deadlineNSecs(); char *buf = new char[256]; - qsnprintf(buf, 256, "%lld.%09d%s", - deadline / 1000 / 1000 / 1000, qAbs(deadline) % (1000 * 1000 * 1000), - dt.hasExpired() ? " (expired)" : ""); + std::snprintf(buf, 256, "%lld.%09lld%s", + deadline / 1000 / 1000 / 1000, + std::abs(deadline) % (1000 * 1000 * 1000), + dt.hasExpired() ? " (expired)" : ""); return buf; } }