Merge pull request #153 from cmaglie/fix_windows_enumerator

windows: Avoid panic if USB Product name is empty
This commit is contained in:
Cristian Maglie
2023-01-03 23:39:20 +01:00
committed by GitHub

View File

@@ -347,11 +347,13 @@ func retrievePortDetailsFromDevInfo(device *deviceInfo, details *PortDetails) er
the result of spdrpFriendlyName is therefore unique and suitable as an alternative string to for a port choice */
n := uint32(0)
setupDiGetDeviceRegistryProperty(device.set, &device.data, spdrpFriendlyName /* spdrpDeviceDesc */, nil, nil, 0, &n)
if n > 0 {
buff := make([]uint16, n*2)
buffP := (*byte)(unsafe.Pointer(&buff[0]))
if setupDiGetDeviceRegistryProperty(device.set, &device.data, spdrpFriendlyName /* spdrpDeviceDesc */, nil, buffP, n, &n) {
details.Product = syscall.UTF16ToString(buff[:])
}
}
return nil
}