summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qtimer.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2025-02-05 22:48:09 +0200
committerAhmad Samir <a.samirh78@gmail.com>2025-03-20 06:18:43 +0200
commitfce5fdb4d1c0e1d2db28d7a8dfb03e916dfc232f (patch)
tree1c4dd28709abeed4f6c7fbd16f73248b61b034cc /src/corelib/kernel/qtimer.cpp
parentbb846a22c37dcb085829676d8feb7c203d21c886 (diff)
QTimer: clamp too-large milliseconds intervals to INT_MAX ms
QTimer stores the interval in an int, a milliseconds interval that is too-large will overflow and the value becomes negative. Clamp the interval to INT_MAX ms. This also matches what QTimer::from_msecs() does. Amends f1f610bc67bfd5c2ef31270a6945e7bae93b5e4a. Change-Id: Id925827f632e8a8d8b8b65e6a41e8f8722344c26 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qtimer.cpp')
-rw-r--r--src/corelib/kernel/qtimer.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp
index 796a82afe0b..74d38faa214 100644
--- a/src/corelib/kernel/qtimer.cpp
+++ b/src/corelib/kernel/qtimer.cpp
@@ -246,9 +246,14 @@ void QTimer::start(int msec)
static std::chrono::milliseconds
checkInterval(const char *caller, std::chrono::milliseconds interval)
{
+ constexpr auto maxInterval = INT_MAX * 1ms;
if (interval < 0ms) {
qWarning("%s: negative intervals aren't allowed; the interval will be set to 1ms.", caller);
interval = 1ms;
+ } else if (interval > maxInterval) {
+ qWarning("%s: interval exceeds maximum allowed interval, it will be clamped to "
+ "INT_MAX ms (about 24 days).", caller);
+ interval = maxInterval;
}
return interval;
}
@@ -276,9 +281,6 @@ void QTimer::start(std::chrono::milliseconds interval)
Q_D(QTimer);
interval = checkInterval("QTimer::start", interval);
-
- // This could be narrowing as the interval is stored in an `int` QProperty,
- // and the type can't be changed in Qt6.
const int msec = interval.count();
const bool intervalChanged = msec != d->inter;
d->inter.setValue(msec);
@@ -645,9 +647,6 @@ void QTimer::setInterval(std::chrono::milliseconds interval)
Q_D(QTimer);
interval = checkInterval("QTimer::setInterval", interval);
-
- // This could be narrowing as the interval is stored in an `int` QProperty,
- // and the type can't be changed in Qt6.
const int msec = interval.count();
d->inter.removeBindingUnlessInWrapper();
const bool intervalChanged = msec != d->inter.valueBypassingBindings();