From 5ae2fbd8e0ace288cf39b966b5b81ab948e00298 Mon Sep 17 00:00:00 2001 From: Artur Mironenko Date: Sat, 13 Jul 2024 20:42:07 +0300 Subject: [PATCH] drop unsafe bytes to str conv --- writer.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/writer.go b/writer.go index 36ef2a3..af13763 100644 --- a/writer.go +++ b/writer.go @@ -6,7 +6,6 @@ import ( "io" "net/http" "time" - "unsafe" "github.com/buger/jsonparser" "github.com/getsentry/sentry-go" @@ -147,17 +146,17 @@ func (w *Writer) parseLogEvent(data []byte) (*sentry.Event, bool) { } err := jsonparser.ObjectEach(data, func(key, value []byte, vt jsonparser.ValueType, offset int) error { - switch string(key) { + switch strKey := string(key); strKey { case zerolog.MessageFieldName: - event.Message = bytesToStrUnsafe(value) + event.Message = string(value) case zerolog.ErrorFieldName: event.Exception = append(event.Exception, sentry.Exception{ - Value: bytesToStrUnsafe(value), + Value: string(value), Stacktrace: newStacktrace(), }) case zerolog.LevelFieldName, zerolog.TimestampFieldName: default: - event.Extra[string(key)] = bytesToStrUnsafe(value) + event.Extra[strKey] = string(value) } return nil @@ -202,10 +201,6 @@ outer: return st } -func bytesToStrUnsafe(data []byte) string { - return *(*string)(unsafe.Pointer(&data)) -} - // WriterOption configures sentry events writer. type WriterOption interface { apply(*config)