From 3a8c0d2cfe795069647234960faaac550d15d042 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 4 Jun 2010 21:40:25 +0200 Subject: [PATCH] Fix ringbuffer number wrap around issue causing buffer items getting overwritten and thus lost. --- src/util-ringbuffer.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/util-ringbuffer.c b/src/util-ringbuffer.c index 91518d5f70..c83b43b607 100644 --- a/src/util-ringbuffer.c +++ b/src/util-ringbuffer.c @@ -113,7 +113,7 @@ int RingBufferMrSw8Put(RingBufferMrSw8 *rb, void *ptr) { SCLogDebug("ptr %p", ptr); /* buffer is full, wait... */ - while ((SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { + while ((unsigned char)(SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { /* break out if the engine wants to shutdown */ if (rb->shutdown != 0) return -1; @@ -200,7 +200,7 @@ int RingBufferMrSwPut(RingBufferMrSw *rb, void *ptr) { SCLogDebug("ptr %p", ptr); /* buffer is full, wait... */ - while ((SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { + while ((unsigned short)(SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { /* break out if the engine wants to shutdown */ if (rb->shutdown != 0) return -1; @@ -259,7 +259,7 @@ void *RingBufferSrSwGet(RingBufferSrSw *rb) { int RingBufferSrSwPut(RingBufferSrSw *rb, void *ptr) { /* buffer is full, wait... */ - while ((SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { + while ((unsigned short)(SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { /* break out if the engine wants to shutdown */ if (rb->shutdown != 0) return -1; @@ -363,7 +363,7 @@ int RingBufferMrMw8Put(RingBufferMrMw8 *rb, void *ptr) { /* buffer is full, wait... */ retry: - while ((SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { + while ((unsigned char)(SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { /* break out if the engine wants to shutdown */ if (rb->shutdown != 0) return -1; @@ -374,7 +374,7 @@ retry: /* get our lock */ SCSpinLock(&rb->spin); /* if while we got our lock the buffer changed, we need to retry */ - if ((SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { + if ((unsigned char)(SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { SCSpinUnlock(&rb->spin); goto retry; } @@ -480,7 +480,7 @@ int RingBufferMrMwPut(RingBufferMrMw *rb, void *ptr) { /* buffer is full, wait... */ retry: - while ((SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { + while ((unsigned short)(SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { /* break out if the engine wants to shutdown */ if (rb->shutdown != 0) return -1; @@ -491,7 +491,7 @@ retry: /* get our lock */ SCSpinLock(&rb->spin); /* if while we got our lock the buffer changed, we need to retry */ - if ((SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { + if ((unsigned short)(SC_ATOMIC_GET(rb->write) + 1) == SC_ATOMIC_GET(rb->read)) { SCSpinUnlock(&rb->spin); goto retry; }