From: Pierre Ossman Date: Tue, 3 Jan 2023 08:27:46 +0000 (+0100) Subject: Add safety check to getNextTimeout() X-Git-Tag: v1.13.90~5^2~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=265c50f5af024d20191eb9d37ee21112593e3aa1;p=tigervnc.git 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. --- 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; }