From 2f1e643229d19f40a5f80dc3784daaff83d5cc02 Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Fri, 19 May 2023 07:31:44 -0400 Subject: [PATCH] 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 --- src/log/slog/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { -- 2.50.0