]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: fix bug in zip.go
authorRobert Griesemer <gri@golang.org>
Mon, 29 Aug 2011 23:49:31 +0000 (16:49 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 29 Aug 2011 23:49:31 +0000 (16:49 -0700)
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

src/cmd/godoc/zip.go

index 27dc142f54063262f4469a0dcd73d033e13cba7c..46d7112e517da75330aa6fe9348d9467b4e60b27 100644 (file)
@@ -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
        }