server: Don't overflow if timeout doesn't fit into int range in get_next_timeout.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2020-09-20 15:59:52 +02:00 committed by Alexandre Julliard
parent b67bbb732b
commit 3541deb0c3
1 changed files with 6 additions and 4 deletions

View File

@ -953,16 +953,18 @@ static int get_next_timeout(void)
if ((ptr = list_head( &abs_timeout_list )) != NULL)
{
struct timeout_user *timeout = LIST_ENTRY( ptr, struct timeout_user, entry );
int diff = (timeout->when - current_time + 9999) / 10000;
if (diff < 0) diff = 0;
timeout_t diff = (timeout->when - current_time + 9999) / 10000;
if (diff > INT_MAX) diff = INT_MAX;
else if (diff < 0) diff = 0;
if (ret == -1 || diff < ret) ret = diff;
}
if ((ptr = list_head( &rel_timeout_list )) != NULL)
{
struct timeout_user *timeout = LIST_ENTRY( ptr, struct timeout_user, entry );
int diff = (-timeout->when - monotonic_time + 9999) / 10000;
if (diff < 0) diff = 0;
timeout_t diff = (-timeout->when - monotonic_time + 9999) / 10000;
if (diff > INT_MAX) diff = INT_MAX;
else if (diff < 0) diff = 0;
if (ret == -1 || diff < ret) ret = diff;
}
}