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 <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/unix/syscall_netbsd.go b/unix/syscall_netbsd.go
index 639bcde..206ce2a 100644
--- a/unix/syscall_netbsd.go
+++ b/unix/syscall_netbsd.go
@@ -100,14 +100,14 @@
}
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)