From a6fb9321ea137e01fb1a702a31d2c6b40b2509a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Wed, 15 Nov 2023 07:00:37 +0100 Subject: [PATCH] audio: fix UB when casting INFINITY to integer Fixes busy wait, because in practice inf would be casted to 0. Fixes: 174df99 --- audio/out/buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/audio/out/buffer.c b/audio/out/buffer.c index 71367e47fd..5b8b523081 100644 --- a/audio/out/buffer.c +++ b/audio/out/buffer.c @@ -698,12 +698,12 @@ static MP_THREAD_VOID playthread(void *arg) // Wait until the device wants us to write more data to it. // Fallback to guessing. - double timeout = INFINITY; + int64_t timeout = INT64_MAX; if (p->streaming && !retry && (!p->paused || ao->stream_silence)) { // Wake up again if half of the audio buffer has been played. // Since audio could play at a faster or slower pace, wake up twice // as often as ideally needed. - timeout = ao->device_buffer / (double)ao->samplerate * 0.25; + timeout = MP_TIME_S_TO_NS(ao->device_buffer / (double)ao->samplerate * 0.25); } mp_mutex_unlock(&p->lock); @@ -715,7 +715,7 @@ static MP_THREAD_VOID playthread(void *arg) } if (!p->need_wakeup && !retry) { MP_STATS(ao, "start audio wait"); - mp_cond_timedwait(&p->pt_wakeup, &p->pt_lock, MP_TIME_S_TO_NS(timeout)); + mp_cond_timedwait(&p->pt_wakeup, &p->pt_lock, timeout); MP_STATS(ao, "end audio wait"); } p->need_wakeup = false;