]> source.dussan.org Git - tigervnc.git/commitdiff
Add safety check to getNextTimeout()
authorPierre Ossman <ossman@cendio.se>
Tue, 3 Jan 2023 08:27:46 +0000 (09:27 +0100)
committerPierre Ossman <ossman@cendio.se>
Wed, 19 Jun 2024 14:39:07 +0000 (16:39 +0200)
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.

common/rfb/Timer.cxx

index d1a6373bca5db12b68ca1e57147499b5c48cfec1..dc17606e7abe1dafd9afb949707c9e19e7b43c27 100644 (file)
@@ -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;
 }