protect against t_diff overflows e.g. after suspends (Steve Hill)
This commit is contained in:
+11
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user