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 TigerVNC#1782.
  • Loading branch information
CendioOssman authored and samhed committed Jul 19, 2024
1 parent c407586 commit 422444a
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 @@ -54,7 +54,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 422444a

Please sign in to comment.