From c3f40e513b63bd484e431984135208106d13c2d3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 10 Apr 2020 12:23:10 +0200 Subject: stream: add assert, a cosmetic change This shouldn't change anything. --- stream/stream.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stream/stream.c b/stream/stream.c index d12ae93338..0a026713f6 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -479,6 +479,7 @@ static int stream_read_unbuffered(stream_t *s, void *buf, int len) s->eof = 1; return 0; } + assert(res <= len); // When reading succeeded we are obviously not at eof. s->eof = 0; s->pos += res; @@ -500,6 +501,7 @@ static bool stream_read_more(struct stream *s, int forward) // Avoid that many small reads will lead to many low-level read calls. forward = MPMAX(forward, s->requested_buffer_size / 2); + assert(forward_avail < forward); // Keep guaranteed seek-back. int buf_old = MPMIN(s->buf_cur - s->buf_start, s->requested_buffer_size / 2); @@ -518,7 +520,7 @@ static bool stream_read_more(struct stream *s, int forward) // Note: read as much as possible, even if forward is much smaller. Do // this because the stream buffer is supposed to set an approx. minimum // read size on it. - int read = buf_alloc - buf_old - forward_avail; // free buffer past end + int read = buf_alloc - (buf_old + forward_avail); // free buffer past end int pos = s->buf_end & s->buffer_mask; read = MPMIN(read, buf_alloc - pos); -- cgit v1.2.3