windows: support ill-formed UTF-16 in UTF16PtrToString
UTF16PtrToString does not support ill-formed UTF-16 because it uses
utf16.Decode, which expects well-formed UTF-16.
This CL updates the UTF16PtrToString implementation to use
UTF16ToString instead of utf16.Decode, which supports ill-formed
UTF-16 since go1.21 via syscall.UTF16ToString.
Change-Id: Ifb72b6d38a8c08ad90ec6a47eed05fc3739500a1
Reviewed-on: https://go-review.googlesource.com/c/sys/+/560355
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go
index ffb8708..6395a03 100644
--- a/windows/syscall_windows.go
+++ b/windows/syscall_windows.go
@@ -125,8 +125,7 @@
for ptr := unsafe.Pointer(p); *(*uint16)(ptr) != 0; n++ {
ptr = unsafe.Pointer(uintptr(ptr) + unsafe.Sizeof(*p))
}
-
- return string(utf16.Decode(unsafe.Slice(p, n)))
+ return UTF16ToString(unsafe.Slice(p, n))
}
func Getpagesize() int { return 4096 }