From 18f54e311551af7e2f01603f3a0758111e826e70 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 21 Sep 2024 21:52:03 +0800 Subject: [PATCH] lint: disable lint checks for string<->bytes conversion temporarily --- internal/bs/bs.go | 8 ++++++-- pkg/pool/byteslice/byteslice.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/bs/bs.go b/internal/bs/bs.go index d23cb34a4..16b3861f7 100644 --- a/internal/bs/bs.go +++ b/internal/bs/bs.go @@ -19,6 +19,10 @@ import ( "unsafe" ) +// TODO(panjf2000): rework the implementation of BytesToString and StringToBytes by +// using unsafe.String/unsafe.StringData and unsafe.Slice/unsafe.SliceData when we +// bump up the minimum required Go version to 1.20. + // BytesToString converts byte slice to a string without memory allocation. // // Note it may break if the implementation of string or slice header changes in the future go versions. @@ -32,9 +36,9 @@ func BytesToString(b []byte) string { // Note it may break if the implementation of string or slice header changes in the future go versions. func StringToBytes(s string) (b []byte) { /* #nosec G103 */ - sh := (*reflect.StringHeader)(unsafe.Pointer(&s)) + sh := (*reflect.StringHeader)(unsafe.Pointer(&s)) //nolint:staticcheck /* #nosec G103 */ - bh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) + bh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) //nolint:staticcheck bh.Data, bh.Len, bh.Cap = sh.Data, sh.Len, sh.Len return b diff --git a/pkg/pool/byteslice/byteslice.go b/pkg/pool/byteslice/byteslice.go index 3fd9ac89b..efd063375 100644 --- a/pkg/pool/byteslice/byteslice.go +++ b/pkg/pool/byteslice/byteslice.go @@ -53,7 +53,7 @@ func (p *Pool) Get(size int) (buf []byte) { if ptr == nil { return make([]byte, 1<