@@ -175,7 +175,7 @@ static void probe_configuration(libusb_device *dev,
175
175
* all devices for non-standard types
176
176
*/
177
177
if (libusb_open (dev, &devh) == 0 ) {
178
- ret = libusb_get_descriptor (devh, USB_DT_DFU, 0 , (void *)&func_dfu,
178
+ ret = libusb_get_descriptor (devh, USB_DT_DFU, 0 , (unsigned char *)&func_dfu,
179
179
sizeof (func_dfu));
180
180
libusb_close (devh);
181
181
if (ret > -1 )
@@ -265,14 +265,14 @@ static void probe_configuration(libusb_device *dev,
265
265
}
266
266
if (intf->iInterface != 0 )
267
267
ret = get_string_descriptor_ascii (devh, intf->iInterface ,
268
- (void *)alt_name, MAX_DESC_STR_LEN);
268
+ (unsigned char *)alt_name, MAX_DESC_STR_LEN);
269
269
else
270
270
ret = -1 ;
271
271
if (ret < 1 )
272
272
strcpy (alt_name, " UNKNOWN" );
273
273
if (desc->iSerialNumber != 0 )
274
274
ret = get_string_descriptor_ascii (
275
- devh, desc->iSerialNumber , (void *)serial_name, MAX_DESC_STR_LEN);
275
+ devh, desc->iSerialNumber , (unsigned char *)serial_name, MAX_DESC_STR_LEN);
276
276
else
277
277
ret = -1 ;
278
278
if (ret < 1 )
@@ -291,7 +291,7 @@ static void probe_configuration(libusb_device *dev,
291
291
continue ;
292
292
}
293
293
294
- pdfu = malloc (sizeof (*pdfu));
294
+ pdfu = (dfu_if *) malloc (sizeof (*pdfu));
295
295
296
296
memset (pdfu, 0 , sizeof (*pdfu));
297
297
@@ -340,9 +340,9 @@ char *get_path(libusb_device *dev) {
340
340
int r, j;
341
341
r = libusb_get_port_numbers (dev, path, sizeof (path));
342
342
if (r > 0 ) {
343
- sprintf (path_buf, " %d-%d" , libusb_get_bus_number (dev), path[0 ]);
343
+ snprintf (path_buf, MAX_PATH_LEN , " %d-%d" , libusb_get_bus_number (dev), path[0 ]);
344
344
for (j = 1 ; j < r; j++) {
345
- sprintf (path_buf + strlen (path_buf), " .%d" , path[j]);
345
+ snprintf (path_buf + strlen (path_buf), MAX_PATH_LEN , " .%d" , path[j]);
346
346
};
347
347
}
348
348
return path_buf;
@@ -354,6 +354,7 @@ char *get_path(libusb_device *dev) {
354
354
}
355
355
356
356
void probe_devices (libusb_context *ctx) {
357
+ dfu_root = NULL ;
357
358
libusb_device **list;
358
359
ssize_t num_devs;
359
360
ssize_t i;
@@ -386,7 +387,7 @@ using namespace std;
386
387
387
388
std::string print_hex (int number) {
388
389
char tmp[10 ];
389
- sprintf (tmp, " 0x%04x" , number);
390
+ snprintf (tmp, 10 , " 0x%04x" , number);
390
391
std::string s (tmp);
391
392
return s;
392
393
}
@@ -461,8 +462,8 @@ void print_list() {
461
462
json previous_list;
462
463
void print_event () {
463
464
auto j = list_dfu_interfaces ();
464
- if (j. size () != previous_list. size ()) {
465
- auto diff = json::diff (j, previous_list);
465
+ auto diff = json::diff (previous_list, j);
466
+ if ( diff. size () > 0 ) {
466
467
std::cout << diff.dump (2 ) << std::endl;
467
468
}
468
469
previous_list = j;
@@ -478,6 +479,9 @@ int main(int argc, char **argv) {
478
479
/* make sure all prints are flushed */
479
480
setvbuf (stdout, NULL , _IONBF, 0 );
480
481
482
+ /* Mute stderr */
483
+ // freopen("/dev/null", "w", stderr);
484
+
481
485
// See
482
486
// https://arduino.github.io/arduino-cli/0.30/pluggable-discovery-specification/
483
487
0 commit comments