From f01f7f6259badb2725be49af914d8db52e025cf6 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 10 Dec 2008 02:47:38 +0200 Subject: [PATCH] ao_alsa: Sanity check get_space() return values better Sometimes after seek audio reset I see snd_pcm_status_get_avail() return huge values. get_space() already had a check againt the value being larger than the whole buffer; however since the unsigned value from the ALSA function had been cast to signed by that point it was interpreted as negative and the check didn't trigger. Use unsigned instead to make the check reliable and ensure the return value is sane. --- libao2/ao_alsa.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libao2/ao_alsa.c b/libao2/ao_alsa.c index 81bcc2c8b3..fdaaac1551 100644 --- a/libao2/ao_alsa.c +++ b/libao2/ao_alsa.c @@ -878,10 +878,10 @@ static int get_space(void) return 0; } - ret = snd_pcm_status_get_avail(status) * bytes_per_sample; - if (ret > ao_data.buffersize) // Buffer underrun? - ret = ao_data.buffersize; - return ret; + unsigned space = snd_pcm_status_get_avail(status) * bytes_per_sample; + if (space > ao_data.buffersize) // Buffer underrun? + space = ao_data.buffersize; + return space; } /* delay in seconds between first and last sample in buffer */