Skip to content

Commit 86cd513

Browse files
committed
Fix C++ errors
1 parent 2bd3fde commit 86cd513

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

main.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static void probe_configuration(libusb_device *dev,
175175
* all devices for non-standard types
176176
*/
177177
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,
179179
sizeof(func_dfu));
180180
libusb_close(devh);
181181
if (ret > -1)
@@ -265,14 +265,14 @@ static void probe_configuration(libusb_device *dev,
265265
}
266266
if (intf->iInterface != 0)
267267
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);
269269
else
270270
ret = -1;
271271
if (ret < 1)
272272
strcpy(alt_name, "UNKNOWN");
273273
if (desc->iSerialNumber != 0)
274274
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);
276276
else
277277
ret = -1;
278278
if (ret < 1)
@@ -291,7 +291,7 @@ static void probe_configuration(libusb_device *dev,
291291
continue;
292292
}
293293

294-
pdfu = malloc(sizeof(*pdfu));
294+
pdfu = (dfu_if *)malloc(sizeof(*pdfu));
295295

296296
memset(pdfu, 0, sizeof(*pdfu));
297297

@@ -340,9 +340,9 @@ char *get_path(libusb_device *dev) {
340340
int r, j;
341341
r = libusb_get_port_numbers(dev, path, sizeof(path));
342342
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]);
344344
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]);
346346
};
347347
}
348348
return path_buf;
@@ -354,6 +354,7 @@ char *get_path(libusb_device *dev) {
354354
}
355355

356356
void probe_devices(libusb_context *ctx) {
357+
dfu_root = NULL;
357358
libusb_device **list;
358359
ssize_t num_devs;
359360
ssize_t i;
@@ -386,7 +387,7 @@ using namespace std;
386387

387388
std::string print_hex(int number) {
388389
char tmp[10];
389-
sprintf(tmp, "0x%04x", number);
390+
snprintf(tmp, 10, "0x%04x", number);
390391
std::string s(tmp);
391392
return s;
392393
}
@@ -461,8 +462,8 @@ void print_list() {
461462
json previous_list;
462463
void print_event() {
463464
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) {
466467
std::cout << diff.dump(2) << std::endl;
467468
}
468469
previous_list = j;
@@ -478,6 +479,9 @@ int main(int argc, char **argv) {
478479
/* make sure all prints are flushed */
479480
setvbuf(stdout, NULL, _IONBF, 0);
480481

482+
/* Mute stderr */
483+
//freopen("/dev/null", "w", stderr);
484+
481485
// See
482486
// https://arduino.github.io/arduino-cli/0.30/pluggable-discovery-specification/
483487

0 commit comments

Comments
 (0)