Skip to content

Commit ca59eda

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
windows: use unsafe.Add instead of pointer arithmetic on a uintptr
The existing uintptr arithmetic is arguably valid because the environment block is not located within the Go heap (see golang/go#58625). However, unsafe.Add (added in Go 1.17) expresses the same logic with fewer conversions, and in addition avoids triggering the unsafeptr vet check. For golang/go#41205. Change-Id: Ifc509279a13fd707be570908ec779d8518b4f75b Reviewed-on: https://go-review.googlesource.com/c/sys/+/492415 Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Bryan Mills <[email protected]>
1 parent 6c52899 commit ca59eda

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

windows/env_windows.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ func (token Token) Environ(inheritExisting bool) (env []string, err error) {
3737
return nil, err
3838
}
3939
defer DestroyEnvironmentBlock(block)
40-
blockp := uintptr(unsafe.Pointer(block))
40+
blockp := unsafe.Pointer(block)
4141
for {
42-
entry := UTF16PtrToString((*uint16)(unsafe.Pointer(blockp)))
42+
entry := UTF16PtrToString((*uint16)(blockp))
4343
if len(entry) == 0 {
4444
break
4545
}
4646
env = append(env, entry)
47-
blockp += 2 * (uintptr(len(entry)) + 1)
47+
blockp = unsafe.Add(blockp, 2*(len(entry)+1))
4848
}
4949
return env, nil
5050
}

0 commit comments

Comments
 (0)