1
0
mirror of https://github.com/golang/go synced 2024-11-25 08:57:58 -07:00

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
This commit is contained in:
Robert Griesemer 2011-08-29 16:49:31 -07:00
parent 58b05e2448
commit 6b90262870

View File

@ -183,9 +183,10 @@ func (z zipList) lookup(name string) (index int, exact bool) {
i := sort.Search(len(z), func(i int) bool { i := sort.Search(len(z), func(i int) bool {
return name <= z[i].Name return name <= z[i].Name
}) })
if i < 0 { if i >= len(z) {
return -1, false return -1, false
} }
// 0 <= i < len(z)
if z[i].Name == name { if z[i].Name == name {
return i, true 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 { j := sort.Search(len(z), func(i int) bool {
return name <= z[i].Name return name <= z[i].Name
}) })
if j < 0 { if j >= len(z) {
return -1, false return -1, false
} }
// 0 <= j < len(z)
if strings.HasPrefix(z[j].Name, name) { if strings.HasPrefix(z[j].Name, name) {
return i + j, false return i + j, false
} }