From: RĂ©mi Denis-Courmont Date: Sun, 10 Aug 2008 12:12:41 +0000 (+0300) Subject: vlc_cond_timedwait: fix unlikely Win32 DWORD overflow X-Git-Tag: 0.9.0~492 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=81df45be607d2fd9078d2896794ed0f4edef3f52;p=vlc vlc_cond_timedwait: fix unlikely Win32 DWORD overflow --- diff --git a/include/vlc_threads.h b/include/vlc_threads.h index 376703da88..675a8ead77 100644 --- a/include/vlc_threads.h +++ b/include/vlc_threads.h @@ -386,14 +386,19 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line, (void)psz_file; (void)i_line; #elif defined( WIN32 ) - mtime_t delay_ms = (deadline - mdate())/1000; + mtime_t total = (deadline - mdate())/1000; DWORD result; - if( delay_ms < 0 ) - delay_ms = 0; + if( total < 0 ) + total = 0; - /* Increase our wait count */ - result = SignalObjectAndWait( *p_mutex, *p_condvar, - delay_ms, FALSE ); + do + { + DWORD delay = (total > 0x7fffffff) ? 0x7fffffff : total; + result = SignalObjectAndWait( *p_mutex, *p_condvar, + delay, FALSE ); + total -= delay; + } + while (total); /* Reacquire the mutex before returning. */ vlc_mutex_lock( p_mutex );