Skip to content

Commit b79cc18

Browse files
committed
code cleanup
1 parent 09c82b4 commit b79cc18

File tree

2 files changed

+3
-18
lines changed

2 files changed

+3
-18
lines changed

pkg/pdh/pdh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ func mszExpandedPathListToStringArr(ptr *uint16) []string {
617617
for *(*uint16)(end) != 0 {
618618
curr, n := utf16PtrToString((*uint16)(end))
619619
result = append(result, curr)
620-
end = unsafe.Pointer(uintptr(n+1)*uintptr(unsafe.Sizeof(*ptr)) + uintptr(end)) //
620+
end = unsafe.Add(end, (n+1)*int(unsafe.Sizeof(*ptr))) //
621621
}
622622
return result
623623
}

pkg/snclient/check_pdh_windows.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import (
66
"regexp"
77
"strconv"
88
"strings"
9-
"syscall"
109
"time"
11-
"unsafe"
1210

1311
"github.com/consol-monitoring/snclient/pkg/pdh"
12+
"golang.org/x/sys/windows"
1413
)
1514

1615
// Check implements CheckHandler.
@@ -123,7 +122,7 @@ func (c *CheckPDH) collectValuesForAllCounters(hQuery pdh.PDH_HQUERY, counters m
123122
if c.OptionalAlias != "" {
124123
name = c.OptionalAlias
125124
} else {
126-
name = strings.Replace(counterPath, "*", utf16PtrToString(fmtValue.SzName), 1)
125+
name = strings.Replace(counterPath, "*", windows.UTF16PtrToString(fmtValue.SzName), 1)
127126
}
128127
entry["name"] = name
129128
entry["value"] = fmt.Sprintf("%d", fmtValue.FmtValue.LargeValue)
@@ -195,17 +194,3 @@ func collectLargeValuesArray(hCounter pdh.PDH_HCOUNTER, hQuery pdh.PDH_HQUERY, r
195194

196195
return filledBuf, ret
197196
}
198-
199-
func utf16PtrToString(ptr *uint16) string {
200-
if ptr == nil {
201-
return ""
202-
}
203-
end := unsafe.Pointer(ptr)
204-
charCounter := 0
205-
for *(*uint16)(end) != 0 {
206-
end = unsafe.Pointer(uintptr(end) + unsafe.Sizeof(*ptr))
207-
charCounter++
208-
}
209-
210-
return syscall.UTF16ToString(unsafe.Slice(ptr, charCounter))
211-
}

0 commit comments

Comments
 (0)