From af653ce8b74f808d092db8ca9741fbb63d2a469d Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 3 Oct 2018 14:28:42 +0000 Subject: [PATCH] unix: use correctly aligned result buffer in SysctlClockinfo It's not guaranteed that the []byte buffer will be aligned as required for Clockinfo. Use a Clockinfo var for the sysctl call instead. This came up during the review for SysctlUvmexp on OpenBSD in CL 139278. Thanks to Ian Lance Taylor for pointing this out. Change-Id: Idc7a624922da7249c6e7d5ce0236a431b58ebe5f Reviewed-on: https://go-review.googlesource.com/c/139279 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Ian Lance Taylor --- unix/syscall_netbsd.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unix/syscall_netbsd.go b/unix/syscall_netbsd.go index 639bcdef..206ce2af 100644 --- a/unix/syscall_netbsd.go +++ b/unix/syscall_netbsd.go @@ -100,14 +100,14 @@ func SysctlClockinfo(name string) (*Clockinfo, error) { } n := uintptr(SizeofClockinfo) - buf := make([]byte, SizeofClockinfo) - if err := sysctl(mib, &buf[0], &n, nil, 0); err != nil { + var ci Clockinfo + if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil { return nil, err } if n != SizeofClockinfo { return nil, EIO } - return (*Clockinfo)(unsafe.Pointer(&buf[0])), nil + return &ci, nil } //sysnb pipe() (fd1 int, fd2 int, err error)