From 6ca8a67f9675fdf350753d703202f5b8cbedc23d Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 24 May 2014 14:02:45 +0200 Subject: timer: remove unneeded time_t overflow check This is mostly covered by the OSX workaround, if the timeout is very high. It also means that with systems using 32 bit time_t, the time will overflow 2036 already, instead of 2037, but we don't consider this a problem. --- osdep/timer.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'osdep/timer.c') diff --git a/osdep/timer.c b/osdep/timer.c index 8dd5915b72..123a78c850 100644 --- a/osdep/timer.c +++ b/osdep/timer.c @@ -91,16 +91,6 @@ static void get_realtime(struct timespec *out_ts) #endif } -// Calculate the maximum of type T, assuming it's a signed integer type and -// represented in 2's complement. -// Works like: (1 << 14) + ((1 << 14) - 1) == (1 << 15) - 1 (but no overflow) -#define SIGNED_MAX(T) ((((T)1) << (sizeof(T) * 8 - 2)) + \ - ((((T)1) << (sizeof(T) * 8 - 2)) - 1)) - -// If you don't like this, go fix POSIX. tv_sec is time_t, but time_t is -// an unknown integer type, and the limits are unknown to the application. -#define MAX_TIME_T SIGNED_MAX(time_t) - struct timespec mp_time_us_to_timespec(int64_t time_us) { struct timespec ts; @@ -119,9 +109,8 @@ struct timespec mp_time_us_to_timespec(int64_t time_us) diff_secs += 1; diff_nsecs -= 1000000000UL; } + // OSX can't deal with large timeouts. Also handles tv_sec/time_t overflows. diff_secs = MPMIN(diff_secs, 10000000); - if (diff_secs > MAX_TIME_T - ts.tv_sec) - diff_secs = MAX_TIME_T - ts.tv_sec; ts.tv_sec += diff_secs; ts.tv_nsec += diff_nsecs; return ts; -- cgit v1.2.3