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