From f012adcefdedd51e7fff87a450d7b38a6c80f1b0 Mon Sep 17 00:00:00 2001 From: Alex In Date: Sat, 24 Aug 2024 22:25:30 +0300 Subject: [PATCH] Use `unsafe.Slice` instead of `reflect.SliceHeader` to build byte slice Signed-off-by: Alex In --- wasm/plugin.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/wasm/plugin.go b/wasm/plugin.go index b63e0a4..6e012df 100644 --- a/wasm/plugin.go +++ b/wasm/plugin.go @@ -13,11 +13,8 @@ import ( ) func PtrToByte(ptr, size uint32) []byte { - var b []byte - s := (*reflect.SliceHeader)(unsafe.Pointer(&b)) - s.Len = uintptr(size) - s.Cap = uintptr(size) - s.Data = uintptr(ptr) + b := unsafe.Slice((*byte)(unsafe.Pointer(uintptr(ptr))), size) + return b }