diff --git a/convert.go b/convert.go index c5460c1..643f2e0 100644 --- a/convert.go +++ b/convert.go @@ -13,25 +13,27 @@ import ( "unsafe" ) -// #nosec G103 // UnsafeString returns a string pointer without allocation func UnsafeString(b []byte) string { // the new way is slower `return unsafe.String(unsafe.SliceData(b), len(b))` // unsafe.Pointer variant: 0.3538 ns/op vs unsafe.String variant: 0.5410 ns/op + // #nosec G103 return *(*string)(unsafe.Pointer(&b)) } -// #nosec G103 // UnsafeBytes returns a byte pointer without allocation. func UnsafeBytes(s string) []byte { + // #nosec G103 return unsafe.Slice(unsafe.StringData(s), len(s)) } // CopyString copies a string to make it immutable func CopyString(s string) string { + // #nosec G103 return string(UnsafeBytes(s)) } +// #nosec G103 // CopyBytes copies a slice to make it immutable func CopyBytes(b []byte) []byte { tmp := make([]byte, len(b)) diff --git a/file.go b/file.go index 0ae8f22..fe44149 100644 --- a/file.go +++ b/file.go @@ -21,7 +21,6 @@ func Walk(fs http.FileSystem, root string, walkFn filepath.WalkFunc) error { return walk(fs, root, info, walkFn) } -// #nosec G304 // ReadFile returns the raw content of a file func ReadFile(path string, fs http.FileSystem) ([]byte, error) { if fs != nil { @@ -32,7 +31,7 @@ func ReadFile(path string, fs http.FileSystem) ([]byte, error) { defer file.Close() return io.ReadAll(file) } - return os.ReadFile(path) + return os.ReadFile(path) // #nosec G304 } // readDirNames reads the directory named by dirname and returns