Skip to content

Commit bb6f761

Browse files
authored
fix(queue): overflow with exit status 1 (#14)
1 parent f1aec4d commit bb6f761

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

datastructure/queue.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package datastructure
22

3-
import "sync"
3+
import (
4+
"fmt"
5+
"os"
6+
"sync"
7+
)
48

59
type queue struct {
610
list []any
@@ -19,6 +23,11 @@ func new(size int) *queue {
1923
func (q *queue) add(k any) {
2024
q.lock.Lock()
2125
defer q.lock.Unlock()
26+
// check if queue is full before adding
27+
if q.lastAdded == len(q.list) {
28+
fmt.Printf("queue is full\n")
29+
os.Exit(1)
30+
}
2231
q.list[q.lastAdded] = k
2332
q.lastAdded++
2433
}

0 commit comments

Comments
 (0)