aboutsummaryrefslogtreecommitdiff
path: root/src/log
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2023-05-19 07:31:44 -0400
committerJonathan Amsterdam <jba@google.com>2023-05-22 18:27:16 +0000
commit2f1e643229d19f40a5f80dc3784daaff83d5cc02 (patch)
tree99f965fe4ad8778bbe0c8f37554a520479637a7d /src/log
parentbc96901e8959c5eb21d5bca5614eb66481815918 (diff)
downloadgo-2f1e643229d19f40a5f80dc3784daaff83d5cc02.tar.gz
go-2f1e643229d19f40a5f80dc3784daaff83d5cc02.zip
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 <gobot@golang.org> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/log')
-rw-r--r--src/log/slog/handler.go2
1 files changed, 1 insertions, 1 deletions
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 {