@@ -418,7 +418,9 @@ static int _modbus_rtu_usb_connect(modbus_t *ctx)
418418 }
419419
420420 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 );
422424 }
423425
424426 for (i = 0 ; i < devs_len ; i ++ ) {
@@ -433,16 +435,16 @@ static int _modbus_rtu_usb_connect(modbus_t *ctx)
433435 if (r != LIBUSB_SUCCESS ) {
434436 if (ctx -> debug ) {
435437 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 ,
438440 libusb_strerror (r ));
439441 }
440442 continue ;
441443 }
442444
443445 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 ,
446448 dev_desc .idVendor ,
447449 dev_desc .idProduct );
448450 }
@@ -461,7 +463,9 @@ static int _modbus_rtu_usb_connect(modbus_t *ctx)
461463 r = libusb_get_port_numbers (d , ud .port_path , sizeof (ud .port_path ));
462464 if (r < 1 ) {
463465 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 );
465469 }
466470 continue ;
467471 }
@@ -477,8 +481,8 @@ static int _modbus_rtu_usb_connect(modbus_t *ctx)
477481 if ((r = libusb_open (d , & dev_handle )) != LIBUSB_SUCCESS ) {
478482 if (ctx -> debug ) {
479483 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 ,
482486 libusb_strerror (r ));
483487 }
484488 continue ;
@@ -540,18 +544,19 @@ static int _modbus_rtu_usb_connect(modbus_t *ctx)
540544
541545 if (is_match ) {
542546 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 );
544548 printf (" Vendor ID: 0x%04x\n" , ud .vid );
545549 printf (" Product ID: 0x%04x\n" , ud .pid );
546550 }
547551
548552 ctx_rtu_usb -> device_handle = dev_handle ;
549553#if defined HAVE_LIBUSB_POLLFD && HAVE_LIBUSB_POLLFD
550554 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 );
552556 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+ }
555560 if (ctx -> debug ) {
556561 printf ("Got a list of %u libusb file descriptors to poll\n" , j );
557562 }
@@ -572,9 +577,10 @@ static int _modbus_rtu_usb_connect(modbus_t *ctx)
572577 }
573578#else
574579 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" );
576582 }
577- #endif /* HAVE_LIBUSB_POLLFD */
583+ #endif /* HAVE_LIBUSB_POLLFD */
578584 break ;
579585 }
580586
0 commit comments