From 0bb40c54348b38d9826fe70d576b34ea7e81ff9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Fernando=20Carri=C3=B3n?= Date: Sun, 29 Aug 2021 20:29:48 +0200 Subject: [PATCH] prevent overflow --- slices/slices.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/slices/slices.go b/slices/slices.go index 7fa4bdf..08dcfa1 100644 --- a/slices/slices.go +++ b/slices/slices.go @@ -39,9 +39,14 @@ func (ps *PtrSlice) Val() interface{} { return ps.current } -func (ps *PtrSlice) Incr() { - ps.idx++ - ps.current = ps.slice.Index(ps.idx).Interface() +func (ps *PtrSlice) Next() { + if ps.idx < ps.length-1 { + ps.idx++ + ps.current = ps.slice.Index(ps.idx).Interface() + } else if ps.idx == ps.length-1 { + ps.idx++ + ps.current = nil + } } func (ps *PtrSlice) Len() int {