Avoid overflow when populating a struct timespec
Unified · Split
| @@ -319,8 +319,9 @@ WELS_THREAD_ERROR_CODE WelsEventWaitWithTimeOut (WELS_EVENT* event, uint32_t · 318 unmodified lines | ||
| 319 | 319 | |
| 320 | 320 | gettimeofday (&tv, 0); |
| 321 | 321 | |
| 322 | − ts.tv_sec = tv.tv_sec + dwMilliseconds / 1000; | |
| 323 | − ts.tv_nsec = tv.tv_usec * 1000 + (dwMilliseconds % 1000) * 1000000; | |
| 322 | + ts.tv_nsec = tv.tv_usec * 1000 + dwMilliseconds * 1000000; | |
| 323 | + ts.tv_sec = tv.tv_sec + ts.tv_nsec / 1000000000; | |
| 324 | + ts.tv_nsec %= 1000000000; | |
| 324 | 325 | |
| 325 | 326 | return sem_timedwait (event, &ts); |
| 326 | 327 | #endif//__APPLE__ |