Skip to content

Commit

Permalink
Fix overflow; "Timer: gettimeofday is broken"
Browse files Browse the repository at this point in the history
The rounding misbehaved when the tv_usec calculation overflows.

Fixes issue #1782.

(cherry picked from commit 422444a)
  • Loading branch information
CendioOssman authored and samhed committed Jul 23, 2024
1 parent 8d0389d commit 75c8701
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion common/rfb/Timer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ inline static timeval addMillis(timeval inTime, int millis) {
}

inline static int diffTimeMillis(timeval later, timeval earlier) {
return ((later.tv_sec - earlier.tv_sec) * 1000) + ((later.tv_usec - earlier.tv_usec + 999) / 1000);
long udiff;
udiff = ((later.tv_sec - earlier.tv_sec) * 1000000) +
(later.tv_usec - earlier.tv_usec);
return (udiff + 999) / 1000;
}

std::list<Timer*> Timer::pending;
Expand Down

0 comments on commit 75c8701

Please sign in to comment.