From 2e076191e5d2478fac8ff553345fc3fc896dfa5a Mon Sep 17 00:00:00 2001 From: divverent Date: Wed, 29 Dec 2010 10:59:30 +0000 Subject: [PATCH] fix the overflow checks in snd_ogg to handle different input and output sampling rates git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10687 d7cf8633-e32d-0410-b094-e92efae38249 --- snd_modplug.c | 6 +++--- snd_ogg.c | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/snd_modplug.c b/snd_modplug.c index ec14ce95..596b38ff 100644 --- a/snd_modplug.c +++ b/snd_modplug.c @@ -341,10 +341,10 @@ static const snd_buffer_t* ModPlug_FetchSound (void *sfxfetcher, void **chfetche // 1- to ensure we won't lose many samples during the resampling process // 2- to reduce calls to ModPlug_FetchSound to regulate workload newlength = (int)(per_sfx->format.speed*STREAM_BUFFER_FILL); - if (newlength + sb->nbframes > sb->maxframes) + if ((size_t) ((double) newlength * (double)sb->format.speed / (double)per_sfx->format.speed) + sb->nbframes > sb->maxframes) { - Con_Printf ("ModPlug_FetchSound: stream buffer overflow (%u sample frames / %u)\n", - sb->format.speed + sb->nbframes, sb->maxframes); + Con_Printf ("ModPlug_FetchSound: stream buffer overflow (%u + %u = %u sample frames / %u)\n", + (unsigned int) ((double) newlength * (double)sb->format.speed / (double)per_sfx->format.speed), sb->nbframes, (unsigned int) ((double) newlength * (double)sb->format.speed / (double)per_sfx->format.speed) + sb->nbframes, sb->maxframes); return NULL; } newlength *= factor; // convert from sample frames to bytes diff --git a/snd_ogg.c b/snd_ogg.c index e383655a..0ee16bab 100644 --- a/snd_ogg.c +++ b/snd_ogg.c @@ -534,10 +534,11 @@ static const snd_buffer_t* OGG_FetchSound (void *sfxfetcher, void **chfetcherpoi // 1- to ensure we won't lose many samples during the resampling process // 2- to reduce calls to OGG_FetchSound to regulate workload newlength = (int)(per_sfx->format.speed*STREAM_BUFFER_FILL); - if (newlength + sb->nbframes > sb->maxframes) + // this is how much we FETCH... + if ((size_t) ((double) newlength * (double)sb->format.speed / (double)per_sfx->format.speed) + sb->nbframes > sb->maxframes) { Con_Printf ("OGG_FetchSound: stream buffer overflow (%u + %u = %u sample frames / %u)\n", - newlength, sb->nbframes, newlength + sb->nbframes, sb->maxframes); + (unsigned int) ((double) newlength * (double)sb->format.speed / (double)per_sfx->format.speed), sb->nbframes, (unsigned int) ((double) newlength * (double)sb->format.speed / (double)per_sfx->format.speed) + sb->nbframes, sb->maxframes); return NULL; } newlength *= factor; // convert from sample frames to bytes -- 2.39.2