Skip to content

Commit

Permalink
windows: support ill-formed UTF-16 in UTF16PtrToString
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
qmuntal committed Feb 1, 2024
1 parent 511ec84 commit 914b96c
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions windows/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 914b96c

Please sign in to comment.