Skip to content

Commit

Permalink
lint: disable lint checks for string<->bytes conversion temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Sep 21, 2024
1 parent 8942638 commit 18f54e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions internal/bs/bs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/pool/byteslice/byteslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (p *Pool) Get(size int) (buf []byte) {
if ptr == nil {
return make([]byte, 1<<idx)[:size]
}
sh := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
sh := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) //nolint:staticcheck
sh.Data = uintptr(ptr)
sh.Len = size
sh.Cap = 1 << idx
Expand Down

0 comments on commit 18f54e3

Please sign in to comment.