diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-03 09:34:00 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-03 09:34:00 +0200 |
commit | 81ca08f1b3ebd3d7b893e0bb39cd00e97827e1f7 (patch) | |
tree | 21e828e10bc0719aaea21b254c308195b229c09f /tun/wintun/guid | |
parent | 2e988467c2c9b7a94369f605bad6b08c70a9df7e (diff) |
setupapi: safer aliasing of slice types
Diffstat (limited to 'tun/wintun/guid')
-rw-r--r-- | tun/wintun/guid/guid_windows.go | 11 | ||||
-rw-r--r-- | tun/wintun/guid/zguid_windows.go | 12 |
2 files changed, 13 insertions, 10 deletions
diff --git a/tun/wintun/guid/guid_windows.go b/tun/wintun/guid/guid_windows.go index 0078d2c..c5f4be6 100644 --- a/tun/wintun/guid/guid_windows.go +++ b/tun/wintun/guid/guid_windows.go @@ -12,7 +12,7 @@ import ( "golang.org/x/sys/windows" ) -//sys clsidFromString(lpsz *uint16, pclsid *windows.GUID) (hr int32) = ole32.CLSIDFromString +//sys clsidFromString(lpsz *uint16, pclsid *windows.GUID) (err error) [failretval!=0] = ole32.CLSIDFromString // // FromString parses "{XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" string to GUID. @@ -22,14 +22,11 @@ func FromString(str string) (*windows.GUID, error) { if err != nil { return nil, err } - guid := &windows.GUID{} - - hr := clsidFromString(strUTF16, guid) - if hr < 0 { - return nil, syscall.Errno(hr) + err = clsidFromString(strUTF16, guid) + if err != nil { + return nil, err } - return guid, nil } diff --git a/tun/wintun/guid/zguid_windows.go b/tun/wintun/guid/zguid_windows.go index 5467849..b0b4cce 100644 --- a/tun/wintun/guid/zguid_windows.go +++ b/tun/wintun/guid/zguid_windows.go @@ -42,8 +42,14 @@ var ( procCLSIDFromString = modole32.NewProc("CLSIDFromString") ) -func clsidFromString(lpsz *uint16, pclsid *windows.GUID) (hr int32) { - r0, _, _ := syscall.Syscall(procCLSIDFromString.Addr(), 2, uintptr(unsafe.Pointer(lpsz)), uintptr(unsafe.Pointer(pclsid)), 0) - hr = int32(r0) +func clsidFromString(lpsz *uint16, pclsid *windows.GUID) (err error) { + r1, _, e1 := syscall.Syscall(procCLSIDFromString.Addr(), 2, uintptr(unsafe.Pointer(lpsz)), uintptr(unsafe.Pointer(pclsid)), 0) + if r1 != 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } return } |