eth/tracers: fix unsafe pointer manipulation for slice creation, close XFN-91 (#1729)

This commit is contained in:
Daniel Liu 2025-11-16 13:53:04 +08:00 committed by benjamin202410
parent 26fb93513d
commit 0ed20eface

View file

@ -44,13 +44,9 @@ const bigIntegerJS = `var bigInt=function(undefined){"use strict";var BASE=1e7,L
// If those are duktape stack items, popping them off **will** make the slice
// contents change.
func makeSlice(ptr unsafe.Pointer, size uint) []byte {
var sl = struct {
addr uintptr
len int
cap int
}{uintptr(ptr), int(size), int(size)}
return *(*[]byte)(unsafe.Pointer(&sl))
// This is the preferred, officially supported, and safer way
// to create a slice from a raw pointer in modern Go versions.
return unsafe.Slice((*byte)(ptr), int(size))
}
// popSlice pops a buffer off the JavaScript stack and returns it as a slice.