From 30dc29e17fb7ad16ecf204c506312e9b01f40f08 Mon Sep 17 00:00:00 2001 From: fztcjjl Date: Thu, 7 May 2020 17:45:48 +0800 Subject: [PATCH] fix ring buffer (#1606) --- util/ring/buffer.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/util/ring/buffer.go b/util/ring/buffer.go index e49f1312..45a7690a 100644 --- a/util/ring/buffer.go +++ b/util/ring/buffer.go @@ -67,17 +67,12 @@ func (b *Buffer) Get(n int) []*Entry { defer b.RUnlock() // reset any invalid values - if n > b.size || n < 0 { - n = b.size + if n > len(b.vals) || n < 0 { + n = len(b.vals) } // create a delta - delta := b.size - n - - // if all the values are less than delta - if len(b.vals) < delta { - return b.vals - } + delta := len(b.vals) - n // return the delta set return b.vals[delta:]