Fix overflow in get_deadline for large (>2000ms) timeouts

This commit is contained in:
Oliver Jowett 2021-04-29 14:52:45 +08:00
parent 265055106b
commit b4acf08738
1 changed files with 2 additions and 1 deletions

3
util.c
View File

@ -93,7 +93,8 @@ void normalize_timespec(struct timespec *ts)
void get_deadline(uint32_t timeout_ms, struct timespec *ts)
{
clock_gettime(CLOCK_REALTIME, ts);
ts->tv_nsec += timeout_ms * 1000000;
ts->tv_sec += timeout_ms / 1000;
ts->tv_nsec += (timeout_ms % 1000) * 1000000;
normalize_timespec(ts);
}