1
0
mirror of https://github.com/golang/go synced 2024-11-21 20:24:50 -07:00

sort: avoid overflow in pivot calculation.

thanks to snilsson@nada.kth.se for the original CL.

R=gri
CC=golang-dev, snilsson
https://golang.org/cl/3280044
This commit is contained in:
Rob Pike 2010-11-30 10:37:57 -08:00
parent 0dc24603eb
commit b389646243

View File

@ -63,7 +63,7 @@ func swapRange(data Interface, a, b, n int) {
}
func doPivot(data Interface, lo, hi int) (midlo, midhi int) {
m := (lo + hi) / 2
m := lo + (hi-lo)/2 // Written like this to avoid integer overflow.
if hi-lo > 40 {
// Tukey's ``Ninther,'' median of three medians of three.
s := (hi - lo) / 8