From 03f44d9f0fdf4654d943231796479e1721b20391 Mon Sep 17 00:00:00 2001 From: Tormod Volden Date: Sun, 12 May 2024 21:39:58 +0200 Subject: [PATCH] examples: Avoid -Wconversion warnings Signed-off-by: Tormod Volden --- examples/dpfp.c | 2 +- examples/ezusb.c | 12 ++++++------ examples/fxload.c | 8 ++++---- examples/sam3u_benchmark.c | 14 +++++++------- examples/xusb.c | 12 ++++++------ 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/dpfp.c b/examples/dpfp.c index 2949383a9..ef67290b2 100644 --- a/examples/dpfp.c +++ b/examples/dpfp.c @@ -535,7 +535,7 @@ static int do_init(void) return r; } - status &= ~0x80; + status &= (unsigned char)~0x80; r = set_hwstat(status); if (r < 0) return r; diff --git a/examples/ezusb.c b/examples/ezusb.c index 4bed12a4c..88eca64cc 100644 --- a/examples/ezusb.c +++ b/examples/ezusb.c @@ -131,7 +131,7 @@ static int ezusb_write(libusb_device_handle *device, const char *label, logerror("%s, addr 0x%08x len %4u (0x%04x)\n", label, addr, (unsigned)len, (unsigned)len); status = libusb_control_transfer(device, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, - opcode, addr & 0xFFFF, addr >> 16, + opcode, addr & 0xFFFF, (uint16_t)(addr >> 16), (unsigned char*)data, (uint16_t)len, 1000); if (status != (signed)len) { if (status < 0) @@ -158,7 +158,7 @@ static int ezusb_read(libusb_device_handle *device, const char *label, logerror("%s, addr 0x%08x len %4u (0x%04x)\n", label, addr, (unsigned)len, (unsigned)len); status = libusb_control_transfer(device, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, - opcode, addr & 0xFFFF, addr >> 16, + opcode, addr & 0xFFFF, (uint16_t)(addr >> 16), (unsigned char*)data, (uint16_t)len, 1000); if (status != (signed)len) { if (status < 0) @@ -186,7 +186,7 @@ static bool ezusb_cpucs(libusb_device_handle *device, uint32_t addr, bool doRun) logerror("%s\n", data ? "stop CPU" : "reset CPU"); status = libusb_control_transfer(device, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, - RW_INTERNAL, addr & 0xFFFF, addr >> 16, + RW_INTERNAL, addr & 0xFFFF, (uint16_t)(addr >> 16), &data, 1, 1000); if ((status != 1) && /* We may get an I/O error from libusb as the device disappears */ @@ -214,7 +214,7 @@ static bool ezusb_fx3_jump(libusb_device_handle *device, uint32_t addr) logerror("transfer execution to Program Entry at 0x%08x\n", addr); status = libusb_control_transfer(device, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, - RW_INTERNAL, addr & 0xFFFF, addr >> 16, + RW_INTERNAL, addr & 0xFFFF, (uint16_t)(addr >> 16), NULL, 0, 1000); /* We may get an I/O error from libusb as the device disappears */ if ((status != 0) && (status != LIBUSB_ERROR_IO)) @@ -463,8 +463,8 @@ static int parse_iic(FILE *image, void *context, logerror("unable to read IIC block header\n"); return -1; } - data_len = (block_header[0] << 8) + block_header[1]; - data_addr = (block_header[2] << 8) + block_header[3]; + data_len = (size_t)(block_header[0] << 8) + block_header[1]; + data_addr = (uint32_t)(block_header[2] << 8) + block_header[3]; if (data_len > sizeof(data)) { /* If this is ever reported as an error, switch to using malloc/realloc */ logerror("IIC data block too small - please report this error to libusb.info\n"); diff --git a/examples/fxload.c b/examples/fxload.c index 252608338..344710d22 100644 --- a/examples/fxload.c +++ b/examples/fxload.c @@ -89,7 +89,7 @@ int main(int argc, char*argv[]) const char *ext, *img_name[] = IMG_TYPE_NAMES; int fx_type = FX_TYPE_UNDEFINED, img_type[ARRAYSIZE(path)]; int opt, status; - unsigned int i, j; + int i, j; unsigned vid = 0, pid = 0; unsigned busnum = 0, devaddr = 0, _busnum, _devaddr; libusb_device *dev, **devs; @@ -199,7 +199,7 @@ int main(int argc, char*argv[]) logerror("examining %04x:%04x (%d,%d)\n", desc.idVendor, desc.idProduct, _busnum, _devaddr); } - for (j=0; jtv_sec = (long)(counter.QuadPart / 1000000ULL); - tv->tv_usec = (long)(counter.QuadPart % 1000000ULL); + tv->tv_sec = (long)(counter.QuadPart / 1000000LL); + tv->tv_usec = (long)(counter.QuadPart % 1000000LL); #elif defined(HAVE_CLOCK_GETTIME) struct timespec ts; @@ -103,7 +103,7 @@ static void LIBUSB_CALL cb_xfr(struct libusb_transfer *xfr) else printf(" "); } - num_bytes += xfr->actual_length; + num_bytes += (unsigned long)xfr->actual_length; num_xfer++; if (libusb_submit_transfer(xfr) < 0) { @@ -130,7 +130,7 @@ static int benchmark_in(uint8_t ep) if (ep == EP_ISO_IN) { libusb_fill_iso_transfer(xfr, devh, ep, buf, sizeof(buf), num_iso_pack, cb_xfr, NULL, 0); - libusb_set_iso_packet_lengths(xfr, sizeof(buf)/num_iso_pack); + libusb_set_iso_packet_lengths(xfr, sizeof(buf)/(unsigned int)num_iso_pack); } else libusb_fill_bulk_transfer(xfr, devh, ep, buf, sizeof(buf), cb_xfr, NULL, 0); @@ -157,15 +157,15 @@ static int benchmark_in(uint8_t ep) static void measure(void) { struct timeval tv_stop; - unsigned long diff_msec; + long diff_msec; get_timestamp(&tv_stop); diff_msec = (tv_stop.tv_sec - tv_start.tv_sec) * 1000L; diff_msec += (tv_stop.tv_usec - tv_start.tv_usec) / 1000L; - printf("%lu transfers (total %lu bytes) in %lu milliseconds => %lu bytes/sec\n", - num_xfer, num_bytes, diff_msec, (num_bytes * 1000L) / diff_msec); + printf("%lu transfers (total %lu bytes) in %ld milliseconds => %lu bytes/sec\n", + num_xfer, num_bytes, diff_msec, (num_bytes * 1000L) / (unsigned long)diff_msec); } static void sig_hdlr(int signum) diff --git a/examples/xusb.c b/examples/xusb.c index 83e5525d7..1a09d43b6 100644 --- a/examples/xusb.c +++ b/examples/xusb.c @@ -50,7 +50,7 @@ static const char* binary_name = NULL; static inline void msleep(int msecs) { #if defined(_WIN32) - Sleep(msecs); + Sleep((DWORD)msecs); #else const struct timespec ts = { msecs / 1000, (msecs % 1000) * 1000000L }; nanosleep(&ts, NULL); @@ -150,7 +150,7 @@ static enum test_type { } test_mode; static uint16_t VID, PID; -static void display_buffer_hex(unsigned char *buffer, unsigned size) +static void display_buffer_hex(unsigned char *buffer, unsigned int size) { unsigned i, j, k; @@ -318,7 +318,7 @@ static int set_xbox_actuators(libusb_device_handle *handle, uint8_t left, uint8_ } static int send_mass_storage_command(libusb_device_handle *handle, uint8_t endpoint, uint8_t lun, - uint8_t *cdb, uint8_t direction, int data_length, uint32_t *ret_tag) + uint8_t *cdb, uint8_t direction, uint32_t data_length, uint32_t *ret_tag) { static uint32_t tag = 1; uint8_t cdb_len; @@ -540,12 +540,12 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in, cdb[8] = 0x01; // 1 block send_mass_storage_command(handle, endpoint_out, lun, cdb, LIBUSB_ENDPOINT_IN, block_size, &expected_tag); - libusb_bulk_transfer(handle, endpoint_in, data, block_size, &size, 5000); + libusb_bulk_transfer(handle, endpoint_in, data, (int)block_size, &size, 5000); printf(" READ: received %d bytes\n", size); if (get_mass_storage_status(handle, endpoint_in, expected_tag) == -2) { get_sense(handle, endpoint_in, endpoint_out); } else { - display_buffer_hex(data, size); + display_buffer_hex(data, (unsigned int)size); if ((binary_dump) && ((fd = fopen(binary_name, "w")) != NULL)) { if (fwrite(data, 1, (size_t)size, fd) != (unsigned int)size) { perr(" unable to write binary data\n"); @@ -603,7 +603,7 @@ static int get_hid_record_size(uint8_t *hid_report_descriptor, int size, int typ } if (found_record_marker) { found_record_marker = false; - record_size[j] += nb_items*nb_bits; + record_size[j] += (int)(nb_items*nb_bits); } } if ((type < HID_REPORT_TYPE_INPUT) || (type > HID_REPORT_TYPE_FEATURE)) {