mirror of
https://github.com/golang/go
synced 2024-11-21 22:14:41 -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 {
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user