bug: avoid overflow when computing mid in the binarySearch of the workerStack (#278)

This commit is contained in:
gocurr 2023-06-08 20:27:59 +08:00 committed by GitHub
parent 9fdd99a7b4
commit 67b3a7a2c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 2 deletions

View File

@ -61,9 +61,8 @@ func (wq *workerStack) refresh(duration time.Duration) []worker {
}
func (wq *workerStack) binarySearch(l, r int, expiryTime time.Time) int {
var mid int
for l <= r {
mid = (l + r) / 2
mid := int(uint(l+r) >> 1) // avoid overflow when computing mid
if expiryTime.Before(wq.items[mid].lastUsedTime()) {
r = mid - 1
} else {