defensive attempt to avoid buffer overruns

This commit is contained in:
Jorj Bauer 2021-01-20 07:42:01 -05:00
parent fc805b57e2
commit c07c24d064

View File

@ -124,8 +124,10 @@ void TeensySpeaker::toggle(int64_t c)
if (newIdx > bufIdx) { if (newIdx > bufIdx) {
long count = (long)newIdx - bufIdx; long count = (long)newIdx - bufIdx;
for (long i=0; i<count; i++) { for (long i=0; i<count; i++) {
if (bufIdx+i+1 < sizeof(soundBuf)/sizeof(short)) {
soundBuf[bufIdx+i] = toggleState ? HIGHVAL : LOWVAL; soundBuf[bufIdx+i] = toggleState ? HIGHVAL : LOWVAL;
} }
}
bufIdx = newIdx; bufIdx = newIdx;
} }
__enable_irq(); __enable_irq();