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 <thiago.macieira@intel.com>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
(cherry picked from commit 61e4be2b62f9b6556a145f226850bf5e62d53e9d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-07-22 15:30:37 +02:00 committed by Qt Cherry-pick Bot
parent c9b55d8b39
commit 57ad4caa7b

View File

@ -10,6 +10,9 @@
#include <QTimer>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <inttypes.h>
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;
}
}