From e14d1f5bc0a0579e8a9934c96a6ca22646da06ac Mon Sep 17 00:00:00 2001 From: Echo J Date: Thu, 1 Aug 2024 20:42:36 +0300 Subject: [PATCH] util: Fix the integer addition in os_time_get_absolute_timeout() This should fix glClientWaitSync() timing out too early with a INT64_MAX timeout on radeonsi Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11615 Fixes: 7316cc92f38 ("gallium/os: add conversion and wait functions for absolute timeouts") Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/util/os_time.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/os_time.c b/src/util/os_time.c index 7daf828580a..da8ad7a80b8 100644 --- a/src/util/os_time.c +++ b/src/util/os_time.c @@ -97,7 +97,9 @@ os_time_get_absolute_timeout(uint64_t timeout) return OS_TIMEOUT_INFINITE; time = os_time_get_nano(); - abs_timeout = time + (int64_t)timeout; + + /* Do the addition in unsigned, because signed overflow is UB, then convert to signed again. */ + abs_timeout = (uint64_t)time + (uint64_t)timeout; /* Check for overflow. */ if (abs_timeout < time)