]> Cypherpunks repositories - gostls13.git/commitdiff
internal/bisect: fix PrintMarker and examples
authorMatthew Dempsky <mdempsky@google.com>
Wed, 9 Aug 2023 08:19:38 +0000 (01:19 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 9 Aug 2023 14:36:30 +0000 (14:36 +0000)
PrintMarker was printing 50 NUL bytes before the marker.

Also, the examples for writing your own ShouldEnable helper suggest
"if m == nil { return false }", but this is inconsistent with how
Matcher.ShouldEnable handles nil pointers.

Change-Id: Ie45075ba7fb8fcc63eadce9d793a06ef0c8aa9f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/517615
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>

src/internal/bisect/bisect.go

index 48c796e54ac7340163a57e427f19ff8bf9398a05..26d3ebf3337cc33b035d8d2b492e0e568ea62b39 100644 (file)
@@ -66,7 +66,7 @@
 //
 //     func ShouldEnable(file string, line int) bool {
 //             if m == nil {
-//                     return false
+//                     return true
 //             }
 //             h := bisect.Hash(file, line)
 //             if m.ShouldPrint(h) {
 //
 //     func ShouldEnable(file string, line int) bool {
 //             if m == nil {
-//                     return false
+//                     return true
 //             }
 //             h := bisect.Hash(file, line)
 //             if m.ShouldPrint(h) {
 //                     if m.MarkerOnly() {
-//                             bisect.PrintMarker(os.Stderr)
+//                             bisect.PrintMarker(os.Stderr, h)
 //                     } else {
 //                             fmt.Fprintf(os.Stderr, "%v %s:%d\n", bisect.Marker(h), file, line)
 //                     }
@@ -495,7 +495,7 @@ type Writer interface {
 // It is appropriate to use when [Matcher.ShouldPrint] and [Matcher.MarkerOnly] both return true.
 func PrintMarker(w Writer, h uint64) error {
        var buf [50]byte
-       b := AppendMarker(buf[:], h)
+       b := AppendMarker(buf[:0], h)
        b = append(b, '\n')
        _, err := w.Write(b)
        return err