mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 20:13:40 +00:00
all: use unsafe.SliceData where appropriate
This commit is contained in:
committed by
Ron Evans
parent
de83d67364
commit
70a0dee8c8
@@ -20,7 +20,7 @@ type reader struct {
|
||||
|
||||
func (r *reader) Read(b []byte) (n int, err error) {
|
||||
if len(b) != 0 {
|
||||
libc_arc4random_buf(unsafe.Pointer(&b[0]), uint(len(b)))
|
||||
libc_arc4random_buf(unsafe.Pointer(unsafe.SliceData(b)), uint(len(b)))
|
||||
}
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func (r *reader) Read(b []byte) (n int, err error) {
|
||||
// See for example: https://github.com/golang/go/issues/33542
|
||||
// For Windows 7 and newer, we might switch to ProcessPrng in the future
|
||||
// (which is a documented function and might be a tiny bit faster).
|
||||
ok := libc_RtlGenRandom(unsafe.Pointer(&b[0]), len(b))
|
||||
ok := libc_RtlGenRandom(unsafe.Pointer(unsafe.SliceData(b)), len(b))
|
||||
if !ok {
|
||||
return 0, errRandom
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) {
|
||||
if len(p) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
libc_arc4random_buf(unsafe.Pointer(&p[0]), uint(len(p)))
|
||||
libc_arc4random_buf(unsafe.Pointer(unsafe.SliceData(p)), uint(len(p)))
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ func execve(pathname string, argv []string, envv []string) error {
|
||||
}
|
||||
env1[len(envv)] = nil
|
||||
|
||||
ret, _, err := syscall.Syscall(syscall.SYS_EXECVE, uintptr(unsafe.Pointer(&argv0[0])), uintptr(unsafe.Pointer(&argv1[0])), uintptr(unsafe.Pointer(&env1[0])))
|
||||
ret, _, err := syscall.Syscall(syscall.SYS_EXECVE, uintptr(unsafe.Pointer(unsafe.SliceData(argv0))), uintptr(unsafe.Pointer(unsafe.SliceData(argv1))), uintptr(unsafe.Pointer(unsafe.SliceData(env1))))
|
||||
if int(ret) != 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ var (
|
||||
putcharBuffer = [putcharBufferSize]byte{}
|
||||
putcharPosition uint = 0
|
||||
putcharIOVec = __wasi_iovec_t{
|
||||
buf: unsafe.Pointer(&putcharBuffer[0]),
|
||||
buf: unsafe.Pointer(unsafe.SliceData(putcharBuffer[:])),
|
||||
}
|
||||
putcharNWritten uint
|
||||
)
|
||||
|
||||
@@ -35,7 +35,7 @@ func os_runtime_args() []string {
|
||||
// Obtain the command line arguments
|
||||
argsSlice := make([]unsafe.Pointer, argc)
|
||||
buf := make([]byte, argv_buf_size)
|
||||
args_get(&argsSlice[0], unsafe.Pointer(&buf[0]))
|
||||
args_get(&argsSlice[0], unsafe.Pointer(unsafe.SliceData(buf)))
|
||||
|
||||
// Convert the array of C strings to an array of Go strings.
|
||||
args = make([]string, argc)
|
||||
|
||||
@@ -280,7 +280,7 @@ func cgo_GoBytes(ptr unsafe.Pointer, length uintptr) []byte {
|
||||
// of upstream Go.
|
||||
buf := make([]byte, length)
|
||||
if length != 0 {
|
||||
memcpy(unsafe.Pointer(&buf[0]), ptr, uintptr(length))
|
||||
memcpy(unsafe.Pointer(unsafe.SliceData(buf)), ptr, uintptr(length))
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, e
|
||||
}
|
||||
|
||||
func Munmap(b []byte) (err error) {
|
||||
errCode := libc_munmap(unsafe.Pointer(&b[0]), uintptr(len(b)))
|
||||
errCode := libc_munmap(unsafe.Pointer(unsafe.SliceData(b)), uintptr(len(b)))
|
||||
if errCode != 0 {
|
||||
err = getErrno()
|
||||
}
|
||||
@@ -237,7 +237,7 @@ func Munmap(b []byte) (err error) {
|
||||
}
|
||||
|
||||
func Mprotect(b []byte, prot int) (err error) {
|
||||
errCode := libc_mprotect(unsafe.Pointer(&b[0]), uintptr(len(b)), int32(prot))
|
||||
errCode := libc_mprotect(unsafe.Pointer(unsafe.SliceData(b)), uintptr(len(b)), int32(prot))
|
||||
if errCode != 0 {
|
||||
err = getErrno()
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ type RawSockaddrInet6 struct {
|
||||
|
||||
func RandomGet(b []byte) error {
|
||||
if len(b) > 0 {
|
||||
libc_arc4random_buf(unsafe.Pointer(&b[0]), uint(len(b)))
|
||||
libc_arc4random_buf(unsafe.Pointer(unsafe.SliceData(b)), uint(len(b)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user