From c3b411fb6b99e91f6f8582f699345806099facf2 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 18 Aug 2016 00:04:07 -0700 Subject: [PATCH] Util: Fix wrap condition on RingFIFORead if it's empty --- src/util/ring-fifo.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/ring-fifo.c b/src/util/ring-fifo.c index ce641e63f..1cb0aedac 100644 --- a/src/util/ring-fifo.c +++ b/src/util/ring-fifo.c @@ -75,6 +75,10 @@ size_t RingFIFORead(struct RingFIFO* buffer, void* output, size_t length) { // Wrap around if we can't fit enough in here if ((intptr_t) data - (intptr_t) buffer->data + length >= buffer->capacity) { + if (end == data) { + // Oops! If we wrap now, it'll appear full + return 0; + } data = buffer->data; }