Windows: return err instead of panic when convert string to utf16
Alexander Morozov authored on 2017/02/07 07:00:00... | ... |
@@ -148,7 +148,13 @@ func callEventRegister() error { |
148 | 148 |
} |
149 | 149 |
|
150 | 150 |
func callEventWriteString(message string) error { |
151 |
- ret, _, _ := procEventWriteString.Call(uintptr(providerHandle), 0, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(message)))) |
|
151 |
+ utf16message, err := syscall.UTF16FromString(message) |
|
152 |
+ |
|
153 |
+ if err != nil { |
|
154 |
+ return err |
|
155 |
+ } |
|
156 |
+ |
|
157 |
+ ret, _, _ := procEventWriteString.Call(uintptr(providerHandle), 0, 0, uintptr(unsafe.Pointer(&utf16message[0]))) |
|
152 | 158 |
if ret != win32CallSuccess { |
153 | 159 |
errorMessage := fmt.Sprintf("ETWLogs provider failed to log message. Error: %d", ret) |
154 | 160 |
logrus.Error(errorMessage) |