Fix OOB read on fast sample generation in MIDI

Valgrind identified cases where the chunk read position came out to be
-1, which was causing a read of memory before the actual cache buffers.
This could result in add'l noise on playback.
This commit is contained in:
Earle F. Philhower, III committed 2020-08-07 21:49:39 -07:00
1 parent 9c654e55cb
commit 33494596a4
1 file changed
+5 -3
+5 -3
View File
@@ -1268,6 +1268,7 @@ short tsf_read_short_cached(tsf *f, int pos)
f->timestamp[repl] = f->epoch++;
f->offset[repl] = readOff;
misses++;
// fprintf(stderr, "buffer[%d][%d-%d = %d]\n", repl, pos, readOff, pos - readOff);
return f->buffer[repl][pos - readOff];
}
@@ -1420,9 +1421,9 @@ static void tsf_voice_render(tsf* f, struct tsf_voice* v, float* outputBuffer, i
}
void DumpF32P32(char *name, long long x) {
printf("%s = %08x.%08x\n", name, (int32_t)((x>>32)&0xffffffff), (int32_t)(x&0xffffffff));
}
//void DumpF32P32(char *name, long long x) {
// printf("%s = %08x.%08x\n", name, (int32_t)((x>>32)&0xffffffff), (int32_t)(x&0xffffffff));
//}
static void tsf_voice_render_fast(tsf* f, struct tsf_voice* v, short* outputBuffer, int numSamples)
{
struct tsf_region* region = v->region;
@@ -1501,6 +1502,7 @@ static void tsf_voice_render_fast(tsf* f, struct tsf_voice* v, short* outputBuff
while (blockSamples-- && tmpSourceSamplePositionF32P32 < tmpSampleEndF32P32)
{
unsigned int pos = (unsigned int)(tmpSourceSamplePositionF32P32>>32);
if (pos == 0xffffffff) pos = 0;
short val = tsf_read_short_cached(f, pos);
int32_t val32 = (int)val * (int)gainMonoFP;