mirror of
https://github.com/golang/go
synced 2024-11-21 21:54:40 -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:
parent
58b05e2448
commit
6b90262870
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user