mirror of
https://github.com/golang/sys.git
synced 2026-02-08 11:46:04 +03:00
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>
This commit is contained in:
committed by
Tobias Klauser
parent
679a27dec1
commit
af653ce8b7
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user