mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
eth/tracers: fix unsafe pointer manipulation for slice creation, close XFN-91 (#1729)
This commit is contained in:
parent
26fb93513d
commit
0ed20eface
1 changed files with 3 additions and 7 deletions
|
|
@ -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.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue