From ee351fa3158708cae5f8bdc285ff3f95058abeca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net> Date: Fri, 3 Jan 2025 12:37:17 -0500 Subject: [PATCH] Make the types correct and eliminate infinite loop. If a write() to the sound device fails (for example USB device goes away), this would loop forever (in it's own thread and whatnot, so you only notice because sounds stops and a core gets used up). --- src/xpdev/xpbeep.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/xpdev/xpbeep.c b/src/xpdev/xpbeep.c index ddd3b6e022..a5d11a9f47 100644 --- a/src/xpdev/xpbeep.c +++ b/src/xpdev/xpbeep.c @@ -833,10 +833,6 @@ do_xp_play_sample(unsigned char *sampo, size_t sz, int *freed) #if defined(WITH_PORTAUDIO) || defined(_WIN32) || defined(WITH_SDL_AUDIO) int need_copy = 0; #endif -#ifdef AFMT_U8 - size_t wr; - int i; -#endif #ifdef WITH_PORTAUDIO if(handle_type==SOUND_DEVICE_PORTAUDIO) { @@ -977,14 +973,14 @@ do_xp_play_sample(unsigned char *sampo, size_t sz, int *freed) #ifdef AFMT_U8 if (handle_type == SOUND_DEVICE_OSS) { + size_t wr = 0; wr = 0; while (wr < sz) { - i = write(dsp, samp + wr, sz - wr); - if (i >= 0) { - if ((SIZE_MAX - i) < wr) - wr = SIZE_MAX; + ssize_t i = write(dsp, samp + wr, sz - wr); + if (i >= 0) wr += i; - } + else + return false; } return true; } -- GitLab