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>
This commit is contained in:
Jonathan Amsterdam 2023-05-19 07:31:44 -04:00
parent bc96901e89
commit 2f1e643229
1 changed files with 1 additions and 1 deletions

View 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 {