diff options
author | wm4 <wm4@nowhere> | 2014-05-24 14:02:45 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-05-24 16:17:45 +0200 |
commit | 6ca8a67f9675fdf350753d703202f5b8cbedc23d (patch) | |
tree | fb91004142800946867c540997451550bdb9e0c8 | |
parent | cec9613505c78e7e5c9d2fe5bcfd59d59e9e91dd (diff) | |
download | mpv-6ca8a67f9675fdf350753d703202f5b8cbedc23d.tar.bz2 mpv-6ca8a67f9675fdf350753d703202f5b8cbedc23d.tar.xz |
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.
-rw-r--r-- | osdep/timer.c | 13 |
1 files changed, 1 insertions, 12 deletions
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; |