diff options
author | Robert Griesemer <gri@golang.org> | 2011-08-29 16:49:31 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2011-08-29 16:49:31 -0700 |
commit | 6b902628709f694967d54045de949d2db20ddadd (patch) | |
tree | 7bc83cccb5cb810652e6a0305d68fb73dc4101c7 | |
parent | 58b05e24482fc206c9473b01dd06c59464cc0b2b (diff) | |
download | go-6b902628709f694967d54045de949d2db20ddadd.tar.gz go-6b902628709f694967d54045de949d2db20ddadd.zip |
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
-rw-r--r-- | src/cmd/godoc/zip.go | 6 |
1 files changed, 4 insertions, 2 deletions
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 } |