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
1 changed files with 3 additions and 1 deletions

View File

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