소스 검색

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>
Tobias Klauser 7 년 전
부모
커밋
af653ce8b7
1개의 변경된 파일3개의 추가작업 그리고 3개의 파일을 삭제
  1. 3 3
      unix/syscall_netbsd.go

+ 3 - 3
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)