scalalang2 / golang-fifo

Modern efficient cache design with simple FIFO queue only in Golang
MIT License
142 stars 7 forks source link

fix: runtime panic "index out of range" caused by nextCleanupBucket #32

Closed Laisky closed 7 months ago

Laisky commented 7 months ago

The type of nextCleanupBucket is int8, if the size is greater than int8, it will result in overflow causing negative numbers, ultimately leading to a program panic.

panic: runtime error: index out of range [-28]

goroutine 104 [running]:
github.com/scalalang2/golang-fifo/sieve.(*Sieve[...]).addToBucket(0xe3ae20, 0xc000496b90)
    /home/laisky.cai/go/pkg/mod/github.com/scalalang2/golang-fifo@v1.0.0/sieve/sieve.go:250 +0x3a7
github.com/scalalang2/golang-fifo/sieve.(*Sieve[...]).Set(0xe3ae20, {0xc000346468, 0x8}, {0xc000346478, 0x8})
    /home/laisky.cai/go/pkg/mod/github.com/scalalang2/golang-fifo@v1.0.0/sieve/sieve.go:117 +0xb91
scalalang2 commented 7 months ago

This changes makes sense to me. Thanks for this improvement 👍