diff options
author | Pierre Ossman <ossman@cendio.se> | 2023-01-03 09:27:46 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2024-06-19 16:39:07 +0200 |
commit | 265c50f5af024d20191eb9d37ee21112593e3aa1 (patch) | |
tree | 1ed0dd7b369dd266a44311dfcbc8daf5977bb8a0 /common | |
parent | bf286837db638a67bde0ab9be0baa621f863b8d5 (diff) | |
download | tigervnc-265c50f5af024d20191eb9d37ee21112593e3aa1.tar.gz tigervnc-265c50f5af024d20191eb9d37ee21112593e3aa1.zip |
Add safety check to getNextTimeout()
It currently won't ever be called with an empty list of timers, but it
is a public function so that might happen in the future. Make sure this
case is handled without crashes.
Diffstat (limited to 'common')
-rw-r--r-- | common/rfb/Timer.cxx | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/common/rfb/Timer.cxx b/common/rfb/Timer.cxx index d1a6373b..dc17606e 100644 --- a/common/rfb/Timer.cxx +++ b/common/rfb/Timer.cxx @@ -104,7 +104,12 @@ int Timer::checkTimeouts() { int Timer::getNextTimeout() { timeval now; gettimeofday(&now, 0); + + if (pending.empty()) + return -1; + int toWait = pending.front()->getRemainingMs(); + if (toWait > pending.front()->timeoutMs) { if (toWait - pending.front()->timeoutMs < 1000) { vlog.info("gettimeofday is broken..."); @@ -115,6 +120,7 @@ int Timer::getNextTimeout() { pending.front()->dueTime = now; toWait = 0; } + return toWait; } |