aboutsummaryrefslogtreecommitdiff
path: root/src/device
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2020-04-04 13:02:18 -0500
committerluigi1111 <luigi1111w@gmail.com>2020-04-04 13:02:18 -0500
commit59ab7692108456fffbfbf3937113e55077d7be08 (patch)
treea4736ee8e4a53eac49b3508c5d6cbc5d7ed69aab /src/device
parentMerge pull request #6361 (diff)
parentdevice: Ledger - fix wide char hidapi error string conversion (diff)
downloadmonero-59ab7692108456fffbfbf3937113e55077d7be08.tar.xz
Merge pull request #6364
6e1cb5a device: Ledger - fix wide char hidapi error string conversion (xiphon)
Diffstat (limited to 'src/device')
-rw-r--r--src/device/device_io_hid.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/device/device_io_hid.cpp b/src/device/device_io_hid.cpp
index 72f4c3bdb..840529c38 100644
--- a/src/device/device_io_hid.cpp
+++ b/src/device/device_io_hid.cpp
@@ -44,8 +44,20 @@ namespace hw {
static std::string safe_hid_error(hid_device *hwdev) {
if (hwdev) {
- const char* error_str = (const char*)hid_error(hwdev);
- return std::string(error_str == nullptr ? "Unknown error" : error_str);
+ const wchar_t* error_wstr = hid_error(hwdev);
+ if (error_wstr == nullptr)
+ {
+ return "Unknown error";
+ }
+ std::mbstate_t state{};
+ const size_t len_symbols = std::wcsrtombs(nullptr, &error_wstr, 0, &state);
+ if (len_symbols == static_cast<std::size_t>(-1))
+ {
+ return "Failed to convert wide char error";
+ }
+ std::string error_str(len_symbols + 1, 0);
+ std::wcsrtombs(&error_str[0], &error_wstr, error_str.size(), &state);
+ return error_str;
}
return std::string("NULL device");
}