]> Cypherpunks repositories - gostls13.git/commitdiff
log/slog: fix check for nil prefix
authorJonathan Amsterdam <jba@google.com>
Fri, 19 May 2023 11:31:44 +0000 (07:31 -0400)
committerJonathan Amsterdam <jba@google.com>
Mon, 22 May 2023 18:27:16 +0000 (18:27 +0000)
Previously, handleState.prefix was nil if and only if the length of
the prefix was zero. Now, prefix is never nil.

Fix the nil check in the code by also checking if the length is non-zero.

Change-Id: I9f69c0029cb1c73fe6c2919c78fee7d4085bfd85
Reviewed-on: https://go-review.googlesource.com/c/go/+/495977
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
src/log/slog/handler.go

index b10a6bd247e62923b1b442f012302e3e2ddaf34d..8cd1e563ebd8eb836771d44ec5f3069335a3f2f7 100644 (file)
@@ -469,7 +469,7 @@ func (s *handleState) appendError(err error) {
 
 func (s *handleState) appendKey(key string) {
        s.buf.WriteString(s.sep)
-       if s.prefix != nil {
+       if s.prefix != nil && len(*s.prefix) > 0 {
                // TODO: optimize by avoiding allocation.
                s.appendString(string(*s.prefix) + key)
        } else {