From 6b6ede656d0bfa607e7e30669b3fb44210a6f4fb Mon Sep 17 00:00:00 2001 From: Joren Date: Tue, 18 Jun 2024 17:49:07 +0200 Subject: [PATCH] -1 error --- ringbuffer/ringbuffer.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ringbuffer/ringbuffer.go b/ringbuffer/ringbuffer.go index b363395..68d8d8a 100644 --- a/ringbuffer/ringbuffer.go +++ b/ringbuffer/ringbuffer.go @@ -77,6 +77,10 @@ func (rb *RingBuffer) ContainsItem(item string) bool { rb.mu.Lock() defer rb.mu.Unlock() + if rb.head == -1 { + return false + } + for i := 0; i < rb.size; i++ { index := (rb.head + i) % rb.size if rb.buffer[index] == item { @@ -86,3 +90,4 @@ func (rb *RingBuffer) ContainsItem(item string) bool { return false } +