@@ -118,13 +118,16 @@ string GlasgowSWDInterface::GetSerialNumber(int index)
118
118
{
119
119
int ret;
120
120
int curr_index = 0 ;
121
- char device_serial[ 64 ] = {} ;
121
+ string serial ;
122
122
123
123
ForEachGlasgowDevice ([&](libusb_device_descriptor *desc, libusb_device_handle *handle) {
124
124
if (curr_index == index ) {
125
+ char serial_array[64 ] = {};
125
126
if ((ret = libusb_get_string_descriptor_ascii (handle, desc->iSerialNumber ,
126
- (uint8_t *)device_serial, sizeof (device_serial))) != 0 ) {
127
- strncpy (device_serial, " (error)" , sizeof (device_serial));
127
+ (uint8_t *)serial_array, sizeof (serial_array))) < 0 ) {
128
+ serial = string (" (error: " ) + libusb_error_name (ret) + " )" ;
129
+ } else {
130
+ serial = string (serial_array, ret);
128
131
}
129
132
130
133
return true ;
@@ -134,7 +137,7 @@ string GlasgowSWDInterface::GetSerialNumber(int index)
134
137
}
135
138
});
136
139
137
- return device_serial ;
140
+ return serial ;
138
141
}
139
142
140
143
string GlasgowSWDInterface::GetDescription (int index)
@@ -216,15 +219,15 @@ GlasgowSWDInterface::GlasgowSWDInterface(const string& serial)
216
219
217
220
char device_serial[64 ];
218
221
if ((ret = libusb_get_string_descriptor_ascii (device_handle, device_desc.iSerialNumber ,
219
- (uint8_t *)device_serial, sizeof (device_serial))) != 0 ) {
222
+ (uint8_t *)device_serial, sizeof (device_serial))) < 0 ) {
220
223
LogError (" Cannot get serial number for Glasgow device %03d:%03d\n " ,
221
224
libusb_get_bus_number (device),
222
225
libusb_get_port_number (device));
223
226
libusb_close (device_handle);
224
227
continue ;
225
228
}
226
229
227
- if (serial == " " || serial == device_serial) {
230
+ if (serial == " " || serial == string ( device_serial, ret) ) {
228
231
m_device = libusb_ref_device (device);
229
232
m_handle = device_handle;
230
233
m_serial = device_serial;
0 commit comments