From bb6f7612ee9d5cd8e287c87e312c380dc7d3785a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?karthick-=E0=AE=95=E0=AE=BE=E0=AE=B0=E0=AF=8D=E0=AE=A4?= =?UTF-8?q?=E0=AF=8D=E0=AE=A4=E0=AE=BF=E0=AE=95=E0=AF=8D?= Date: Sat, 20 Jul 2024 13:19:04 +0100 Subject: [PATCH] fix(queue): overflow with exit status 1 (#14) --- datastructure/queue.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/datastructure/queue.go b/datastructure/queue.go index 87ca28d..797f36a 100644 --- a/datastructure/queue.go +++ b/datastructure/queue.go @@ -1,6 +1,10 @@ package datastructure -import "sync" +import ( + "fmt" + "os" + "sync" +) type queue struct { list []any @@ -19,6 +23,11 @@ func new(size int) *queue { func (q *queue) add(k any) { q.lock.Lock() defer q.lock.Unlock() + // check if queue is full before adding + if q.lastAdded == len(q.list) { + fmt.Printf("queue is full\n") + os.Exit(1) + } q.list[q.lastAdded] = k q.lastAdded++ }