Skip to content

Commit 2ff63b3

Browse files
committed
windows/svc: fix manager config toStringSlice pointer casting
1 parent f1d8baa commit 2ff63b3

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

windows/svc/mgr/config.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package mgr
88

99
import (
1010
"syscall"
11-
"unicode/utf16"
1211
"unsafe"
1312

1413
"golang.org/x/sys/windows"
@@ -51,20 +50,23 @@ func toString(p *uint16) string {
5150
}
5251

5352
func toStringSlice(ps *uint16) []string {
54-
if ps == nil {
55-
return nil
56-
}
5753
r := make([]string, 0)
58-
for from, i, p := 0, 0, (*[1 << 24]uint16)(unsafe.Pointer(ps)); true; i++ {
59-
if p[i] == 0 {
60-
// empty string marks the end
61-
if i <= from {
62-
break
63-
}
64-
r = append(r, string(utf16.Decode(p[from:i])))
65-
from = i + 1
54+
p := unsafe.Pointer(ps)
55+
56+
offset := func(count int) uintptr {
57+
return unsafe.Sizeof(uint16(0)) * (uintptr)(count)
58+
}
59+
60+
for {
61+
s := windows.UTF16PtrToString((*uint16)(p), 4096)
62+
if s == "" {
63+
break
6664
}
65+
66+
r = append(r, s)
67+
p = unsafe.Pointer(uintptr(p) + offset(len(s)+1))
6768
}
69+
6870
return r
6971
}
7072

0 commit comments

Comments
 (0)