From: Robert Griesemer Date: Mon, 29 Aug 2011 23:49:31 +0000 (-0700) Subject: godoc: fix bug in zip.go X-Git-Tag: weekly.2011-09-01~26 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6b902628709f694967d54045de949d2db20ddadd;p=gostls13.git godoc: fix bug in zip.go The result of sort.Search is in the interval [0,n); specifically, if no entry is found, the result is n and not -1. R=dsymonds CC=golang-dev https://golang.org/cl/4982041 --- diff --git a/src/cmd/godoc/zip.go b/src/cmd/godoc/zip.go index 27dc142f54..46d7112e51 100644 --- a/src/cmd/godoc/zip.go +++ b/src/cmd/godoc/zip.go @@ -183,9 +183,10 @@ func (z zipList) lookup(name string) (index int, exact bool) { i := sort.Search(len(z), func(i int) bool { return name <= z[i].Name }) - if i < 0 { + if i >= len(z) { return -1, false } + // 0 <= i < len(z) if z[i].Name == name { return i, true } @@ -196,9 +197,10 @@ func (z zipList) lookup(name string) (index int, exact bool) { j := sort.Search(len(z), func(i int) bool { return name <= z[i].Name }) - if j < 0 { + if j >= len(z) { return -1, false } + // 0 <= j < len(z) if strings.HasPrefix(z[j].Name, name) { return i + j, false }