fix (streams): fixed bug in max readable bytes calculation

This commit is contained in:
antifallobst 2023-04-30 11:52:30 +02:00
parent 1777ca2150
commit aa5ca306ca
1 changed files with 2 additions and 2 deletions

View File

@ -47,11 +47,11 @@ uint32_t stream_read(stream_T* stream, void* buffer_out, uint32_t n) {
uint32_t num_bottom; uint32_t num_bottom;
if (stream->pos_sender > stream->pos_receiver) { if (stream->pos_sender > stream->pos_receiver) {
num_top = MIN(n, stream->pos_sender - stream->pos_receiver - 1); num_top = MIN(n, stream->pos_sender - stream->pos_receiver);
num_bottom = 0; num_bottom = 0;
} else { } else {
num_top = MIN(n, stream->size - stream->pos_receiver); num_top = MIN(n, stream->size - stream->pos_receiver);
num_bottom = MIN(n - num_top, stream->pos_sender - 1); num_bottom = MIN(n - num_top, stream->pos_sender);
} }
memory_copy(&stream->buffer[stream->pos_receiver], buffer_out, num_top); memory_copy(&stream->buffer[stream->pos_receiver], buffer_out, num_top);