aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqmuntal <qmuntaldiaz@microsoft.com>2024-02-01 15:05:25 +0100
committerQuim Muntal <quimmuntal@gmail.com>2024-02-01 17:02:20 +0000
commit914b96c1bddd0738464c043cccbbac14fc94b955 (patch)
treeecf04eb178d31d855b1522b89d1bdd7df883915f
parent511ec846b66e39447acbd021083b26ca2747a188 (diff)
downloadgolang-x-sys-914b96c1bddd0738464c043cccbbac14fc94b955.tar.gz
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>
-rw-r--r--windows/syscall_windows.go3
1 files changed, 1 insertions, 2 deletions
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 @@ func UTF16PtrToString(p *uint16) string {
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 }