From: Jonathan Amsterdam Date: Fri, 19 May 2023 11:31:44 +0000 (-0400) Subject: log/slog: fix check for nil prefix X-Git-Tag: go1.21rc1~379 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2f1e643229d19f40a5f80dc3784daaff83d5cc02;p=gostls13.git log/slog: fix check for nil prefix 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 Run-TryBot: Jonathan Amsterdam Reviewed-by: Alan Donovan --- diff --git a/src/log/slog/handler.go b/src/log/slog/handler.go index b10a6bd247..8cd1e563eb 100644 --- a/src/log/slog/handler.go +++ b/src/log/slog/handler.go @@ -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 {