Skip to content

Commit e3ee246

Browse files
Orange-iMacOrange-iMac
Orange-iMac
authored and
Orange-iMac
committed
fix sciter.Value SetString wrong lenght of encoded utf16 []byte
1 parent 4fcee17 commit e3ee246

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

sciter.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,8 +1866,9 @@ func (pdst *Value) SetString(str string, uintType ...int) error {
18661866
}
18671867
cpdst := (*C.VALUE)(unsafe.Pointer(pdst))
18681868
// args
1869-
chars := (C.LPCWSTR)(unsafe.Pointer(StringToUTF16Ptr(str)))
1870-
numChars := (C.UINT)(len(str))
1869+
pStr, length := StringToUTF16PtrWithLen(str)
1870+
chars := (C.LPCWSTR)(unsafe.Pointer(pStr))
1871+
numChars := (C.UINT)(length)
18711872
// cgo call
18721873
return wrapValueResult(VALUE_RESULT(C.ValueStringDataSet(cpdst, chars, numChars, sType)), "ValueStringDataSet")
18731874
}

utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ func StringToUTF16Ptr(s string) *uint16 {
7878
return &us[0]
7979
}
8080

81+
func StringToUTF16PtrWithLen(s string) (*uint16, int) {
82+
us, _ := Utf16FromString(s)
83+
length := len(us) - 1
84+
return &us[0], length
85+
}
86+
8187
func BytePtrToBytes(bp *byte, size uint) []byte {
8288
bs := []byte{}
8389
p := uintptr(unsafe.Pointer(bp))

0 commit comments

Comments
 (0)