From 0f1850ec6e42945ea13eb15dcc6358728105cd82 Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Fri, 12 Feb 2010 13:27:09 +0000 Subject: [PATCH] fixed potential buffer overflow when using resampling (FM High-Quality mode). --- source/sound/sound.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/sound/sound.c b/source/sound/sound.c index 6cf25a4..abbdc85 100644 --- a/source/sound/sound.c +++ b/source/sound/sound.c @@ -187,12 +187,11 @@ int sound_update(unsigned int cycles) /* resynchronize FM & PSG chips */ YM2612Update(Fir_Resampler_buffer(), remain); Fir_Resampler_write(remain << 1); + fm_cycles_count = psg_cycles_count; } - fm_cycles_count = psg_cycles_count; - #ifdef LOGSOUND - error("%d FM samples available\n",Fir_Resampler_written() >> 1); + error("%d FM samples available (%d needed)\n",Fir_Resampler_written() >> 1, remain); #endif } else @@ -210,7 +209,7 @@ int sound_update(unsigned int cycles) error("%lu FM cycles run \n",fm_cycles_count); #endif - /* adjust PSG & FM cycle counts */ + /* adjust PSG & FM cycle counts for next frame */ psg_cycles_count -= (cycles << 11); fm_cycles_count -= (cycles << 11);