From 288fd6eb9d16cc29b0370f4a0b5e3e499521d502 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Wed, 9 Aug 2023 01:19:38 -0700 Subject: [PATCH] internal/bisect: fix PrintMarker and examples 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 Reviewed-by: David Chase Run-TryBot: Matthew Dempsky --- src/internal/bisect/bisect.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/internal/bisect/bisect.go b/src/internal/bisect/bisect.go index 48c796e54a..26d3ebf333 100644 --- a/src/internal/bisect/bisect.go +++ b/src/internal/bisect/bisect.go @@ -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) { @@ -83,12 +83,12 @@ // // 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 -- 2.50.0