@@ -418,7 +418,9 @@ static int _modbus_rtu_usb_connect(modbus_t *ctx)
418
418
}
419
419
420
420
if (ctx -> debug ) {
421
- printf ("Number of USB devices: %ld\n" , devs_len );
421
+ // Here and below: cast from ssize_t to a portable type big enough for expected
422
+ // values
423
+ printf ("Number of USB devices: %lld\n" , (long long int ) devs_len );
422
424
}
423
425
424
426
for (i = 0 ; i < devs_len ; i ++ ) {
@@ -433,16 +435,16 @@ static int _modbus_rtu_usb_connect(modbus_t *ctx)
433
435
if (r != LIBUSB_SUCCESS ) {
434
436
if (ctx -> debug ) {
435
437
fprintf (stderr ,
436
- "libusb_get_device_descriptor for device #%ld failed: %s\n" ,
437
- i ,
438
+ "libusb_get_device_descriptor for device #%lld failed: %s\n" ,
439
+ ( long long int ) i ,
438
440
libusb_strerror (r ));
439
441
}
440
442
continue ;
441
443
}
442
444
443
445
if (ctx -> debug ) {
444
- printf ("Considering device #%ld (%04x:%04x)\n" ,
445
- i ,
446
+ printf ("Considering device #%lld (%04x:%04x)\n" ,
447
+ ( long long int ) i ,
446
448
dev_desc .idVendor ,
447
449
dev_desc .idProduct );
448
450
}
@@ -461,7 +463,9 @@ static int _modbus_rtu_usb_connect(modbus_t *ctx)
461
463
r = libusb_get_port_numbers (d , ud .port_path , sizeof (ud .port_path ));
462
464
if (r < 1 ) {
463
465
if (ctx -> debug ) {
464
- fprintf (stderr , "libusb_get_port_numbers for device #%ld failed\n" , i );
466
+ fprintf (stderr ,
467
+ "libusb_get_port_numbers for device #%lld failed\n" ,
468
+ (long long int ) i );
465
469
}
466
470
continue ;
467
471
}
@@ -477,8 +481,8 @@ static int _modbus_rtu_usb_connect(modbus_t *ctx)
477
481
if ((r = libusb_open (d , & dev_handle )) != LIBUSB_SUCCESS ) {
478
482
if (ctx -> debug ) {
479
483
fprintf (stderr ,
480
- "libusb_open for device #%ld failed: %s\n" ,
481
- i ,
484
+ "libusb_open for device #%lld failed: %s\n" ,
485
+ ( long long int ) i ,
482
486
libusb_strerror (r ));
483
487
}
484
488
continue ;
@@ -540,18 +544,19 @@ static int _modbus_rtu_usb_connect(modbus_t *ctx)
540
544
541
545
if (is_match ) {
542
546
if (ctx -> debug ) {
543
- printf ("Found Device %ld (Path %s):\n" , i , path_buffer );
547
+ printf ("Found Device %lld (Path %s):\n" , ( long long int ) i , path_buffer );
544
548
printf (" Vendor ID: 0x%04x\n" , ud .vid );
545
549
printf (" Product ID: 0x%04x\n" , ud .pid );
546
550
}
547
551
548
552
ctx_rtu_usb -> device_handle = dev_handle ;
549
553
#if defined HAVE_LIBUSB_POLLFD && HAVE_LIBUSB_POLLFD
550
554
if (usb_ctx ) {
551
- const struct libusb_pollfd * * pollfds = libusb_get_pollfds (usb_ctx );
555
+ const struct libusb_pollfd * * pollfds = libusb_get_pollfds (usb_ctx );
552
556
if (pollfds ) {
553
- unsigned j ;
554
- for (j = 0 ; pollfds [j ] != NULL ; j ++ ) {}
557
+ unsigned j ;
558
+ for (j = 0 ; pollfds [j ] != NULL ; j ++ ) {
559
+ }
555
560
if (ctx -> debug ) {
556
561
printf ("Got a list of %u libusb file descriptors to poll\n" , j );
557
562
}
@@ -572,9 +577,10 @@ static int _modbus_rtu_usb_connect(modbus_t *ctx)
572
577
}
573
578
#else
574
579
if (ctx -> debug ) {
575
- printf ("Can not get a list of libusb file descriptors to poll from this libusb version\n" );
580
+ printf ("Can not get a list of libusb file descriptors to poll from this "
581
+ "libusb version\n" );
576
582
}
577
- #endif /* HAVE_LIBUSB_POLLFD */
583
+ #endif /* HAVE_LIBUSB_POLLFD */
578
584
break ;
579
585
}
580
586
0 commit comments