avoid off-by-one error when overwriting w/loop

This commit is contained in:
Paul Davis 2020-05-13 18:52:07 -06:00
parent 7232ac2f67
commit 7660ea29d2

View file

@ -692,8 +692,16 @@ DiskReader::overwrite_existing_audio ()
chunk1_offset = overwrite_offset;
chunk1_cnt = min (c->front()->rbuf->bufsize() - overwrite_offset, to_overwrite);
/* note: because we are overwriting buffer contents but not moving the
* write/read pointers, we do actually want to fill all the way to the
* write pointer (the value given by PlaybackBuffer::overwritable_at().
*
* This differs from what happens during ::refill_audio() where we are
* careful not to allow the read pointer to catch the write pointer
* (that indicates an empty buffer)
*/
if (chunk1_cnt == to_overwrite) {
chunk1_cnt--;
chunk2_cnt = 0;
} else {
chunk2_cnt = to_overwrite - chunk1_cnt;