From f5b90b0d3a941bf7b15de41e38ef39a2d974cf3b Mon Sep 17 00:00:00 2001 From: marschap Date: Wed, 20 Sep 2006 08:59:34 +0000 Subject: [PATCH] protect against t_diff overflows e.g. after suspends (Steve Hill) --- server/main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/main.c b/server/main.c index b1c66bf..24b93c4 100644 --- a/server/main.c +++ b/server/main.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "getopt.h" @@ -814,7 +815,16 @@ do_mainloop(void) last_t = t; #ifndef WIN32 gettimeofday (&t, NULL); - t_diff = ((t.tv_sec - last_t.tv_sec) * 1e6 + (t.tv_usec - last_t.tv_usec)); + t_diff = t.tv_sec - last_t.tv_sec; + if ((t_diff + 1) > (LONG_MAX / 1e6)) { + /* We're going to overflow the calculation - probably been to sleep, fudge the values */ + t_diff = 0; + process_lag = 1; + render_lag = (1e6/RENDER_FREQ); + } else { + t_diff *= 1e6; + t_diff += t.tv_usec - last_t.tv_usec; + } #else QueryPerformanceCounter(&t); /*t_diff.HighPart = t.HighPart - last_t.HighPart;