diff --git a/src/crypto/rand/rand_arc4random.go b/src/crypto/rand/rand_arc4random.go index ada1a96192..96fe230846 100644 --- a/src/crypto/rand/rand_arc4random.go +++ b/src/crypto/rand/rand_arc4random.go @@ -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 } diff --git a/src/crypto/rand/rand_windows.go b/src/crypto/rand/rand_windows.go index d8c9173c1e..e40ae855b0 100644 --- a/src/crypto/rand/rand_windows.go +++ b/src/crypto/rand/rand_windows.go @@ -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 } diff --git a/src/internal/syscall/unix/getrandom_wasi.go b/src/internal/syscall/unix/getrandom_wasi.go index 1aab2ab10d..e38845b3b1 100644 --- a/src/internal/syscall/unix/getrandom_wasi.go +++ b/src/internal/syscall/unix/getrandom_wasi.go @@ -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 } diff --git a/src/os/osexec.go b/src/os/osexec.go index 57139d1b64..6b2562a685 100644 --- a/src/os/osexec.go +++ b/src/os/osexec.go @@ -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 } diff --git a/src/runtime/runtime_tinygowasm.go b/src/runtime/runtime_tinygowasm.go index 67367b479e..fedf80e777 100644 --- a/src/runtime/runtime_tinygowasm.go +++ b/src/runtime/runtime_tinygowasm.go @@ -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 ) diff --git a/src/runtime/runtime_wasip1.go b/src/runtime/runtime_wasip1.go index d680fad17e..e8371b7ae3 100644 --- a/src/runtime/runtime_wasip1.go +++ b/src/runtime/runtime_wasip1.go @@ -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) diff --git a/src/runtime/string.go b/src/runtime/string.go index 1136ef94a4..d4ee5e3c1a 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -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 } diff --git a/src/syscall/syscall_libc.go b/src/syscall/syscall_libc.go index 2e8f5e3112..00b52e44cd 100644 --- a/src/syscall/syscall_libc.go +++ b/src/syscall/syscall_libc.go @@ -260,7 +260,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() } @@ -268,7 +268,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() } diff --git a/src/syscall/syscall_libc_wasi.go b/src/syscall/syscall_libc_wasi.go index 479377877b..6675ff9616 100644 --- a/src/syscall/syscall_libc_wasi.go +++ b/src/syscall/syscall_libc_wasi.go @@ -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 }