From 7098ab7d2d14b6d7d50c0e4b99f8cc8c37e5cf88 Mon Sep 17 00:00:00 2001 From: Our Air Quality Date: Mon, 17 Jun 2024 00:51:59 +1000 Subject: [PATCH] readmembuf: wrap around before comparing to the write pointer otherwise this breaks when the write pointer is index 0. --- src/stream.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/stream.c b/src/stream.c index f6d815edf..04442524b 100644 --- a/src/stream.c +++ b/src/stream.c @@ -2525,17 +2525,16 @@ static void closemembuf(membuf_t *membuf) /* read memory buffer --------------------------------------------------------*/ static int readmembuf(membuf_t *membuf, uint8_t *buff, int n, char *msg) { - int i,nr=0; - tracet(4,"readmembuf: n=%d\n",n); if (!membuf) return 0; rtklib_lock(&membuf->lock); - for (i=membuf->rp;i!=membuf->wp&&nr=membuf->bufsize) i=0; + size_t i=membuf->rp, nr=0; + while (i!=membuf->wp&&nrbuf[i]; + if (++i>=membuf->bufsize) i=0; } membuf->rp=i; rtklib_unlock(&membuf->lock);