summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoonchild <mcwerewolf@gmail.com>2018-09-20 00:37:18 +0200
committerGitHub <noreply@github.com>2018-09-20 00:37:18 +0200
commit4f89ce5af980776cdf6900280c0fcf52c70e84c1 (patch)
treee96f63a7528cd59ff23039655c089be14b492040
parent4b90811978c29d8dae05c8b4bc76d8616e8d73c4 (diff)
parent7214d60a1266d1ddd7ef2be6ae80a04a9a01ee03 (diff)
downloadUXP-4f89ce5af980776cdf6900280c0fcf52c70e84c1.tar
UXP-4f89ce5af980776cdf6900280c0fcf52c70e84c1.tar.gz
UXP-4f89ce5af980776cdf6900280c0fcf52c70e84c1.tar.lz
UXP-4f89ce5af980776cdf6900280c0fcf52c70e84c1.tar.xz
UXP-4f89ce5af980776cdf6900280c0fcf52c70e84c1.zip
Merge pull request #778 from MihailZenkov/master
Fix timer overflow on converting from sec to msec in idleService
-rw-r--r--widget/nsIdleService.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/widget/nsIdleService.cpp b/widget/nsIdleService.cpp
index a1a2566df..f9904d39c 100644
--- a/widget/nsIdleService.cpp
+++ b/widget/nsIdleService.cpp
@@ -46,6 +46,10 @@ using namespace mozilla;
// Number of seconds in a day.
#define SECONDS_PER_DAY 86400
+// MAX_DELTA_SEC * 1000 should be less than UINT32_MAX to prevent overflow on
+// converting from sec to msec
+#define MAX_DELTA_SEC (SECONDS_PER_DAY * 10)
+
static PRLogModuleInfo *sLog = nullptr;
#define LOG_TAG "GeckoIdleService"
@@ -391,7 +395,7 @@ nsIdleService::GetInstance()
nsIdleService::nsIdleService() : mCurrentlySetToTimeoutAt(TimeStamp()),
mIdleObserverCount(0),
- mDeltaToNextIdleSwitchInS(UINT32_MAX),
+ mDeltaToNextIdleSwitchInS(MAX_DELTA_SEC),
mLastUserInteraction(TimeStamp::Now())
{
if (sLog == nullptr)
@@ -544,7 +548,7 @@ nsIdleService::ResetIdleTimeOut(uint32_t idleDeltaInMS)
// Mark all idle services as non-idle, and calculate the next idle timeout.
nsCOMArray<nsIObserver> notifyList;
- mDeltaToNextIdleSwitchInS = UINT32_MAX;
+ mDeltaToNextIdleSwitchInS = MAX_DELTA_SEC;
// Loop through all listeners, and find any that have detected idle.
for (uint32_t i = 0; i < mArrayListeners.Length(); i++) {
@@ -717,7 +721,7 @@ nsIdleService::IdleTimerCallback(void)
}
// We need to initialise the time to the next idle switch.
- mDeltaToNextIdleSwitchInS = UINT32_MAX;
+ mDeltaToNextIdleSwitchInS = MAX_DELTA_SEC;
// Create list of observers that should be notified.
nsCOMArray<nsIObserver> notifyList;
@@ -839,7 +843,7 @@ void
nsIdleService::ReconfigureTimer(void)
{
// Check if either someone is idle, or someone will become idle.
- if ((mIdleObserverCount == 0) && UINT32_MAX == mDeltaToNextIdleSwitchInS) {
+ if ((mIdleObserverCount == 0) && MAX_DELTA_SEC == mDeltaToNextIdleSwitchInS) {
// If not, just let any existing timers run to completion
// And bail out.
MOZ_LOG(sLog, LogLevel::Debug,