Skip to content

Commit

Permalink
bug: avoid overflow when computing mid in the binarySearch of the wor…
Browse files Browse the repository at this point in the history
…kerStack (#278)
  • Loading branch information
callthingsoff committed Jun 8, 2023
1 parent 9fdd99a commit 67b3a7a
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions worker_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 67b3a7a

Please sign in to comment.