Commit af653ce8 authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 679a27de
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment