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 // If those are duktape stack items, popping them off **will** make the slice
// contents change. // contents change.
func makeSlice(ptr unsafe.Pointer, size uint) []byte { func makeSlice(ptr unsafe.Pointer, size uint) []byte {
var sl = struct { // This is the preferred, officially supported, and safer way
addr uintptr // to create a slice from a raw pointer in modern Go versions.
len int return unsafe.Slice((*byte)(ptr), int(size))
cap int
}{uintptr(ptr), int(size), int(size)}
return *(*[]byte)(unsafe.Pointer(&sl))
} }
// popSlice pops a buffer off the JavaScript stack and returns it as a slice. // popSlice pops a buffer off the JavaScript stack and returns it as a slice.