From 1fa1edf16b24ea758d66b19b43e9697163c80a70 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 16 Dec 2007 19:30:57 -0800 Subject: Fix ring buffer size and overrun detection --- Alc/alcRing.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Alc/alcRing.c b/Alc/alcRing.c index 0e52ad3c..c2384a83 100644 --- a/Alc/alcRing.c +++ b/Alc/alcRing.c @@ -70,7 +70,7 @@ void DestroyRingBuffer(RingBuffer *ring) ALsizei RingBufferSize(RingBuffer *ring) { - return (ring->read_pos+1-ring->write_pos+ring->length) % ring->length; + return (ring->write_pos-ring->read_pos-1+ring->length) % ring->length; } void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len) @@ -79,8 +79,8 @@ void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len) EnterCriticalSection(&ring->cs); - if((ring->write_pos-ring->read_pos+ring->length)%ring->length < len) - ring->read_pos = ((ring->write_pos+len) % ring->length) + 1; + if((ring->read_pos-ring->write_pos+ring->length)%ring->length < len) + ring->read_pos = (ring->write_pos+len) % ring->length; if(remain < len) { -- cgit v1.2.3