]> Cypherpunks.ru repositories - gostls13.git/commit
log/slog: create prefix buffer earlier
authorJonathan Amsterdam <jba@google.com>
Wed, 10 May 2023 00:56:09 +0000 (20:56 -0400)
committerJonathan Amsterdam <jba@google.com>
Tue, 16 May 2023 18:01:59 +0000 (18:01 +0000)
commit6fc5e7d4b52986f82ec25d5993ff7f8bde8b61f5
tree929e29615ceea641a871734fff310659079f3e7d
parenta3e95f3b509e59a814bbc8073664d46739869e2e
log/slog: create prefix buffer earlier

It's possible that the replacement for a built-in attribute is a Group.
That would cause a nil pointer exception because the handleState.prefix
field isn't set until later, in appendNonBuiltIns.

So create the prefix field earlier, at the start of commonHandler.handle.

Once we do this, we can simplify the code by creating and freeing the
prefix in newHandleState.

Along the way I discovered a line that wasn't being tested:
state.prefix.WriteString(h.groupPrefix)
so I modified an existing test case to cover it.

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