aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2010-11-30 10:37:57 -0800
committerRob Pike <r@golang.org>2010-11-30 10:37:57 -0800
commitb3896462435fde33f20b36131e4a94f61a9fe803 (patch)
tree06ce536630d7f6494112fa4b88c20e7cb1043a5d
parent0dc24603ebe5d8d51690c6af4e2b94ff761ae9b6 (diff)
downloadgo-b3896462435fde33f20b36131e4a94f61a9fe803.tar.gz
go-b3896462435fde33f20b36131e4a94f61a9fe803.zip
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
-rw-r--r--src/pkg/sort/sort.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/pkg/sort/sort.go b/src/pkg/sort/sort.go
index c5b848414a..2abe22d5c7 100644
--- a/src/pkg/sort/sort.go
+++ b/src/pkg/sort/sort.go
@@ -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