Skip to content

Commit

Permalink
examples: Avoid -Wconversion warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Tormod Volden <[email protected]>
  • Loading branch information
tormodvolden committed May 12, 2024
1 parent 182ec89 commit 03f44d9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/dpfp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions examples/ezusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions examples/fxload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; j<ARRAYSIZE(known_device); j++) {
for (j=0; j<(int)ARRAYSIZE(known_device); j++) {
if ((desc.idVendor == known_device[j].vid)
&& (desc.idProduct == known_device[j].pid)) {
if (// nothing was specified
Expand All @@ -219,7 +219,7 @@ int main(int argc, char*argv[])
}
}
}
if (j < ARRAYSIZE(known_device)) {
if (j < (int)ARRAYSIZE(known_device)) {
if (verbose)
logerror("found device '%s' [%04x:%04x] (%d,%d)\n",
known_device[j].designation, vid, pid, busnum, devaddr);
Expand Down Expand Up @@ -260,7 +260,7 @@ int main(int argc, char*argv[])
if (verbose)
logerror("microcontroller type: %s\n", fx_name[fx_type]);

for (i=0; i<ARRAYSIZE(path); i++) {
for (i=0; i<(int)ARRAYSIZE(path); i++) {
if (path[i] != NULL) {
ext = path[i] + strlen(path[i]) - 4;
if ((_stricmp(ext, ".hex") == 0) || (strcmp(ext, ".ihx") == 0))
Expand Down
14 changes: 7 additions & 7 deletions examples/sam3u_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ static void get_timestamp(struct timeval *tv)
counter.QuadPart *= 1000000;
counter.QuadPart /= frequency.QuadPart;

tv->tv_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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions examples/xusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 03f44d9

Please sign in to comment.