initialize the timespec struct in do_gettime() function

in case of clock_gettime() failure the values may be random

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-04-27 20:23:28 +03:00
parent c5e97acf49
commit 6558a31ae6

View file

@ -48,7 +48,7 @@ QElapsedTimer::ClockType QElapsedTimer::clockType()
static inline void do_gettime(qint64 *sec, qint64 *frac) static inline void do_gettime(qint64 *sec, qint64 *frac)
{ {
struct timespec ts; struct timespec ts = { 0, 0 };
if (Q_LIKELY(QElapsedTimer::isMonotonic())) { if (Q_LIKELY(QElapsedTimer::isMonotonic())) {
::clock_gettime(CLOCK_MONOTONIC, &ts); ::clock_gettime(CLOCK_MONOTONIC, &ts);
} else { } else {
@ -112,7 +112,7 @@ qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const
{ {
qint64 secs = other.t1 - t1; qint64 secs = other.t1 - t1;
qint64 fraction = other.t2 - t2; qint64 fraction = other.t2 - t2;
return (secs * Q_INT64_C(1000000000) + fraction) / Q_INT64_C(1000000);; return (secs * Q_INT64_C(1000000000) + fraction) / Q_INT64_C(1000000);
} }
qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const