protect against t_diff overflows e.g. after suspends (Steve Hill)

This commit is contained in:
marschap
2006-09-20 08:59:34 +00:00
parent 29b70ee8d6
commit f5b90b0d3a
+11 -1
View File
@@ -43,6 +43,7 @@
#include <sys/types.h>
#include <fcntl.h>
#include <sys/types.h>
#include <limits.h>
#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;