aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-10-12 11:44:08 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2021-10-12 11:44:08 -0600
commitd0663c3c94ba75a6d11312fd24dfd2713c9b431b (patch)
tree5a968153526b7e898f46405dd09f0a3e97171909
parentmanager: use newer wireguard-go APIs (diff)
downloadwireguard-windows-d0663c3c94ba75a6d11312fd24dfd2713c9b431b.tar.xz
wireguard-windows-d0663c3c94ba75a6d11312fd24dfd2713c9b431b.zip
global: use unsafe.Add where possible
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--conf/dpapi/dpapi_windows.go4
-rw-r--r--conf/dpapi/dpapi_windows_test.go2
-rw-r--r--driver/configuration_windows.go6
-rw-r--r--elevate/privileges.go2
-rw-r--r--ui/syntax/highlighter.go2
-rw-r--r--version/official.go2
6 files changed, 9 insertions, 9 deletions
diff --git a/conf/dpapi/dpapi_windows.go b/conf/dpapi/dpapi_windows.go
index b8e6af4b..951f8693 100644
--- a/conf/dpapi/dpapi_windows.go
+++ b/conf/dpapi/dpapi_windows.go
@@ -61,8 +61,8 @@ func Decrypt(data []byte, name string) ([]byte, error) {
if *a == 0 || *b == 0 {
break
}
- a = (*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer(a)) + 2))
- b = (*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer(b)) + 2))
+ a = (*uint16)(unsafe.Add(unsafe.Pointer(a), 2))
+ b = (*uint16)(unsafe.Add(unsafe.Pointer(b), 2))
}
runtime.KeepAlive(utf16Name)
windows.LocalFree(windows.Handle(unsafe.Pointer(outName)))
diff --git a/conf/dpapi/dpapi_windows_test.go b/conf/dpapi/dpapi_windows_test.go
index 351b4d8f..a9122314 100644
--- a/conf/dpapi/dpapi_windows_test.go
+++ b/conf/dpapi/dpapi_windows_test.go
@@ -53,7 +53,7 @@ func TestRoundTrip(t *testing.T) {
if err != nil {
t.Errorf("Unable to get utf16 chars for name: %s", err)
}
- nameUtf16Bytes := unsafe.Slice((*byte)(unsafe.Pointer(&nameUtf16[0])), len(nameUtf16) * 2)
+ nameUtf16Bytes := unsafe.Slice((*byte)(unsafe.Pointer(&nameUtf16[0])), len(nameUtf16)*2)
i := bytes.Index(eCorrupt, nameUtf16Bytes)
if i == -1 {
t.Error("Unable to find ad in blob")
diff --git a/driver/configuration_windows.go b/driver/configuration_windows.go
index 2029c75a..893cab13 100644
--- a/driver/configuration_windows.go
+++ b/driver/configuration_windows.go
@@ -127,7 +127,7 @@ func (wireguard *Adapter) Configuration() (interfaze *Interface, err error) {
// FirstPeer returns the first peer attached to the interface.
func (interfaze *Interface) FirstPeer() *Peer {
- return (*Peer)(unsafe.Pointer(uintptr(unsafe.Pointer(interfaze)) + unsafe.Sizeof(*interfaze)))
+ return (*Peer)(unsafe.Add(unsafe.Pointer(interfaze), unsafe.Sizeof(*interfaze)))
}
// NextPeer returns the subsequent peer of the current one.
@@ -137,12 +137,12 @@ func (peer *Peer) NextPeer() *Peer {
// FirstAllowedIP returns the first allowed IP attached to the peer.
func (peer *Peer) FirstAllowedIP() *AllowedIP {
- return (*AllowedIP)(unsafe.Pointer(uintptr(unsafe.Pointer(peer)) + unsafe.Sizeof(*peer)))
+ return (*AllowedIP)(unsafe.Add(unsafe.Pointer(peer), unsafe.Sizeof(*peer)))
}
// NextAllowedIP returns the subsequent allowed IP of the current one.
func (allowedIP *AllowedIP) NextAllowedIP() *AllowedIP {
- return (*AllowedIP)(unsafe.Pointer(uintptr(unsafe.Pointer(allowedIP)) + unsafe.Sizeof(*allowedIP)))
+ return (*AllowedIP)(unsafe.Add(unsafe.Pointer(allowedIP), unsafe.Sizeof(*allowedIP)))
}
type ConfigBuilder struct {
diff --git a/elevate/privileges.go b/elevate/privileges.go
index 5c4cd69f..8fc38555 100644
--- a/elevate/privileges.go
+++ b/elevate/privileges.go
@@ -44,7 +44,7 @@ func DropAllPrivileges(retainDriverLoading bool) error {
}
tokenPrivileges := (*windows.Tokenprivileges)(unsafe.Pointer(&buffer[0]))
for i := uint32(0); i < tokenPrivileges.PrivilegeCount; i++ {
- item := (*windows.LUIDAndAttributes)(unsafe.Pointer(uintptr(unsafe.Pointer(&tokenPrivileges.Privileges[0])) + unsafe.Sizeof(tokenPrivileges.Privileges[0])*uintptr(i)))
+ item := (*windows.LUIDAndAttributes)(unsafe.Add(unsafe.Pointer(&tokenPrivileges.Privileges[0]), unsafe.Sizeof(tokenPrivileges.Privileges[0])*uintptr(i)))
if retainDriverLoading && item.Luid == luid {
continue
}
diff --git a/ui/syntax/highlighter.go b/ui/syntax/highlighter.go
index a531854b..47946093 100644
--- a/ui/syntax/highlighter.go
+++ b/ui/syntax/highlighter.go
@@ -62,7 +62,7 @@ type stringSpan struct {
}
func (s stringSpan) at(i int) *byte {
- return (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(s.s)) + uintptr(i)))
+ return (*byte)(unsafe.Add(unsafe.Pointer(s.s), uintptr(i)))
}
func (s stringSpan) isSame(c string) bool {
diff --git a/version/official.go b/version/official.go
index 5998124c..00089ca0 100644
--- a/version/official.go
+++ b/version/official.go
@@ -146,7 +146,7 @@ func extractCertificatePolicies(path string, oid string) ([]string, error) {
return nil, err
}
for i := uintptr(0); i < uintptr(certPoliciesInfo.Count); i++ {
- cp := (*windows.CertPolicyInfo)(unsafe.Pointer(uintptr(unsafe.Pointer(certPoliciesInfo.PolicyInfos)) + i*unsafe.Sizeof(*certPoliciesInfo.PolicyInfos)))
+ cp := (*windows.CertPolicyInfo)(unsafe.Add(unsafe.Pointer(certPoliciesInfo.PolicyInfos), i*unsafe.Sizeof(*certPoliciesInfo.PolicyInfos)))
policies = append(policies, windows.BytePtrToString(cp.Identifier))
}
}