diff options
Diffstat (limited to 'src/audio/chunk.cpp')
| -rw-r--r-- | src/audio/chunk.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/audio/chunk.cpp b/src/audio/chunk.cpp index baf2aba5..fb7f1354 100644 --- a/src/audio/chunk.cpp +++ b/src/audio/chunk.cpp @@ -25,6 +25,7 @@ ChunkReader::~ChunkReader() { auto ChunkReader::HandleNewData(cpp::span<std::byte> data) -> cpp::span<std::byte> { + assert(leftover_bytes_ + data.size() <= working_buffer_.size()); // Copy the new data onto the front for anything that was left over from the // last portion. Note: this could be optimised for the '0 leftover bytes' // case, which technically shouldn't need a copy. @@ -40,10 +41,8 @@ auto ChunkReader::HandleLeftovers(std::size_t bytes_used) -> void { leftover_bytes_ = last_data_in_working_buffer_.size() - bytes_used; if (leftover_bytes_ > 0) { auto data_to_keep = last_data_in_working_buffer_.last(leftover_bytes_); - // Copy backwards, since if more than half of the data was unused then the - // source and destination will overlap. - std::copy_backward(data_to_keep.begin(), data_to_keep.end(), - working_buffer_.begin()); + std::copy(data_to_keep.begin(), data_to_keep.end(), + working_buffer_.begin()); } } |
