GeezerVison is showing github.com — Fix most remaining Clang -Wsign-conversion warnings · Raghuvardhan-Reddy78/libusb@bc1ddf4
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: examples/ezusb.c +3-5Lines changed: 3 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -442,8 +442,6 @@ static int parse_iic(FILE *image, void *context, | 442 | 442 | int (*poke)(void *context, uint32_t addr, bool external, const unsigned char *data, size_t len)) | 443 | 443 | { | 444 | 444 | unsigned char data[4096]; | 445 | | - uint32_t data_addr = 0; | 446 | | - size_t data_len = 0, read_len; | 447 | 445 | uint8_t block_header[4]; | 448 | 446 | int rc; | 449 | 447 | bool external = false; | @@ -466,14 +464,14 @@ static int parse_iic(FILE *image, void *context, | 466 | 464 | logerror("unable to read IIC block header\n"); | 467 | 465 | return -1; | 468 | 466 | } | 469 | | - data_len = (block_header[0] << 8) + block_header[1]; | 470 | | - data_addr = (block_header[2] << 8) + block_header[3]; | | 467 | + size_t data_len = (size_t)((block_header[0] << 8) + block_header[1]); | | 468 | + uint32_t data_addr = (uint32_t)((block_header[2] << 8) + block_header[3]); | 471 | 469 | if (data_len > sizeof(data)) { | 472 | 470 | /* If this is ever reported as an error, switch to using malloc/realloc */ | 473 | 471 | logerror("IIC data block too small - please report this error to libusb.info\n"); | 474 | 472 | return -1; | 475 | 473 | } | 476 | | - read_len = fread(data, 1, data_len, image); | | 474 | + size_t read_len = fread(data, 1, data_len, image); | 477 | 475 | if (read_len != data_len) { | 478 | 476 | logerror("read error\n"); | 479 | 477 | return -1; | |
Collapse file Copy file name to clipboardExpand all lines: examples/fxload.c +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -94,7 +94,6 @@ int main(int argc, char*argv[]) | 94 | 94 | const char *ext, *img_name[] = IMG_TYPE_NAMES; | 95 | 95 | int fx_type = FX_TYPE_UNDEFINED, img_type[ARRAYSIZE(path)]; | 96 | 96 | int opt, status; | 97 | | - unsigned int i, j; | 98 | 97 | unsigned vid = 0, pid = 0; | 99 | 98 | unsigned busnum = 0, devaddr = 0, _busnum, _devaddr; | 100 | 99 | libusb_device *dev, **devs; | @@ -164,6 +163,7 @@ int main(int argc, char*argv[]) | 164 | 163 |
| 165 | 164 | /* determine the target type */ | 166 | 165 | if (type != NULL) { | | 166 | + int i; | 167 | 167 | for (i=0; i<FX_TYPE_MAX; i++) { | 168 | 168 | if (strcmp(type, fx_name[i]) == 0) { | 169 | 169 | fx_type = i; | @@ -190,7 +190,7 @@ int main(int argc, char*argv[]) | 190 | 190 | logerror("libusb_get_device_list() failed: %s\n", libusb_error_name(status)); | 191 | 191 | goto err; | 192 | 192 | } | 193 | | - for (i=0; (dev=devs[i]) != NULL; i++) { | | 193 | + for (unsigned int i=0; (dev=devs[i]) != NULL; i++) { | 194 | 194 | _busnum = libusb_get_bus_number(dev); | 195 | 195 | _devaddr = libusb_get_device_address(dev); | 196 | 196 | if ((type != NULL) && (device_path != NULL)) { | @@ -200,6 +200,7 @@ int main(int argc, char*argv[]) | 200 | 200 | } else { | 201 | 201 | status = libusb_get_device_descriptor(dev, &desc); | 202 | 202 | if (status >= 0) { | | 203 | + unsigned int j; | 203 | 204 | if (verbose >= 3) { | 204 | 205 | logerror("examining %04x:%04x (%d,%d)\n", | 205 | 206 | desc.idVendor, desc.idProduct, _busnum, _devaddr); | @@ -265,7 +266,7 @@ int main(int argc, char*argv[]) | 265 | 266 | if (verbose) | 266 | 267 | logerror("microcontroller type: %s\n", fx_name[fx_type]); | 267 | 268 |
| 268 | | - for (i=0; i<ARRAYSIZE(path); i++) { | | 269 | + for (unsigned int i=0; i<ARRAYSIZE(path); i++) { | 269 | 270 | if (path[i] != NULL) { | 270 | 271 | ext = path[i] + strlen(path[i]) - 4; | 271 | 272 | if ((libusb_strcasecmp(ext, ".hex") == 0) || (libusb_strcasecmp(ext, ".ihx") == 0)) | |
Collapse file Copy file name to clipboardExpand all lines: examples/sam3u_benchmark.c +4-6Lines changed: 4 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -106,7 +106,7 @@ static void LIBUSB_CALL cb_xfr(struct libusb_transfer *xfr) | 106 | 106 | else | 107 | 107 | printf(" "); | 108 | 108 | } | 109 | | - num_bytes += xfr->actual_length; | | 109 | + num_bytes += (unsigned long)xfr->actual_length; | 110 | 110 | num_xfer++; | 111 | 111 |
| 112 | 112 | if (libusb_submit_transfer(xfr) < 0) { | @@ -133,7 +133,7 @@ static int benchmark_in(uint8_t ep) | 133 | 133 | if (ep == EP_ISO_IN) { | 134 | 134 | libusb_fill_iso_transfer(xfr, devh, ep, buf, | 135 | 135 | sizeof(buf), num_iso_pack, cb_xfr, NULL, 0); | 136 | | - libusb_set_iso_packet_lengths(xfr, sizeof(buf)/num_iso_pack); | | 136 | + libusb_set_iso_packet_lengths(xfr, sizeof(buf)/(unsigned int)num_iso_pack); | 137 | 137 | } else | 138 | 138 | libusb_fill_bulk_transfer(xfr, devh, ep, buf, | 139 | 139 | sizeof(buf), cb_xfr, NULL, 0); | @@ -160,14 +160,12 @@ static int benchmark_in(uint8_t ep) | 160 | 160 | static void measure(void) | 161 | 161 | { | 162 | 162 | struct timeval tv_stop; | 163 | | - unsigned long diff_msec; | 164 | | - | 165 | 163 | get_timestamp(&tv_stop); | 166 | 164 |
| 167 | | - diff_msec = (tv_stop.tv_sec - tv_start.tv_sec) * 1000L; | | 165 | + long diff_msec = (tv_stop.tv_sec - tv_start.tv_sec) * 1000L; | 168 | 166 | diff_msec += (tv_stop.tv_usec - tv_start.tv_usec) / 1000L; | 169 | 167 |
| 170 | | - printf("%lu transfers (total %lu bytes) in %lu milliseconds => %lu bytes/sec\n", | | 168 | + printf("%lu transfers (total %lu bytes) in %lu milliseconds => %ld bytes/sec\n", | 171 | 169 | num_xfer, num_bytes, diff_msec, (num_bytes * 1000L) / diff_msec); | 172 | 170 | } | 173 | 171 |
| |
Collapse file Copy file name to clipboardExpand all lines: examples/xusb.c +4-5Lines changed: 4 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -78,8 +78,7 @@ static void perr(char const *format, ...) | 78 | 78 | #define CALL_CHECK(fcall) do { int _r=fcall; if (_r < 0) ERR_EXIT(_r); } while (0) | 79 | 79 | #define CALL_CHECK_CLOSE(fcall, hdl) do { int _r=fcall; if (_r < 0) { libusb_close(hdl); ERR_EXIT(_r); } } while (0) | 80 | 80 | #define B(x) (((x)!=0)?1:0) | 81 | | -#define be_to_int32(buf) (((buf)[0]<<24)|((buf)[1]<<16)|((buf)[2]<<8)|(buf)[3]) | 82 | | - | | 81 | +#define be_to_int32(buf) ((uint32_t)((((uint32_t)(buf)[0])<<24) | (((uint32_t)(buf)[1])<<16) | (((uint32_t)(buf)[2])<<8) | ((uint32_t)(buf)[3]))) | 83 | 82 | #define RETRY_MAX 5 | 84 | 83 | #define REQUEST_SENSE_LENGTH 0x12 | 85 | 84 | #define INQUIRY_LENGTH 0x24 | @@ -326,7 +325,7 @@ static int set_xbox_actuators(libusb_device_handle *handle, uint8_t left, uint8_ | 326 | 325 | } | 327 | 326 |
| 328 | 327 | static int send_mass_storage_command(libusb_device_handle *handle, uint8_t endpoint, uint8_t lun, | 329 | | - uint8_t *cdb, uint8_t direction, int data_length, uint32_t *ret_tag) | | 328 | + uint8_t *cdb, uint8_t direction, uint32_t data_length, uint32_t *ret_tag) | 330 | 329 | { | 331 | 330 | static uint32_t tag = 1; | 332 | 331 | uint8_t cdb_len; | @@ -548,12 +547,12 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in, | 548 | 547 | cdb[8] = 0x01; // 1 block | 549 | 548 |
| 550 | 549 | send_mass_storage_command(handle, endpoint_out, lun, cdb, LIBUSB_ENDPOINT_IN, block_size, &expected_tag); | 551 | | - libusb_bulk_transfer(handle, endpoint_in, data, block_size, &size, 5000); | | 550 | + libusb_bulk_transfer(handle, endpoint_in, data, (int)block_size, &size, 5000); | 552 | 551 | printf(" READ: received %d bytes\n", size); | 553 | 552 | if (get_mass_storage_status(handle, endpoint_in, expected_tag) == -2) { | 554 | 553 | get_sense(handle, endpoint_in, endpoint_out); | 555 | 554 | } else { | 556 | | - display_buffer_hex(data, size); | | 555 | + display_buffer_hex(data, (unsigned int)size); | 557 | 556 | if (binary_dump) { | 558 | 557 | fd = fopen(binary_name, "w"); | 559 | 558 | if (fd != NULL) { | |
Collapse file Copy file name to clipboardExpand all lines: libusb/libusb.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1525,7 +1525,7 @@ struct libusb_transfer { | 1525 | 1525 |
| 1526 | 1526 | /** Actual length of data that was transferred. Read-only, and only for | 1527 | 1527 | * use within transfer callback function. Not valid for isochronous | 1528 | | - * endpoint transfers. */ | | 1528 | + * endpoint transfers. Never negative. */ | 1529 | 1529 | int actual_length; | 1530 | 1530 |
| 1531 | 1531 | /** Callback function. This will be invoked when the transfer completes, | |
Collapse file Copy file name to clipboardExpand all lines: libusb/os/events_posix.c +8-6Lines changed: 8 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 |
| 24 | 24 | #include "libusbi.h" | 25 | 25 |
| | 26 | +#include <assert.h> | 26 | 27 | #include <errno.h> | 27 | 28 | #include <fcntl.h> | 28 | 29 | #ifdef HAVE_EVENTFD | @@ -258,7 +259,6 @@ int usbi_wait_for_events(struct libusb_context *ctx, | 258 | 259 | { | 259 | 260 | struct pollfd *fds = (struct pollfd *)ctx->event_data; | 260 | 261 | usbi_nfds_t nfds = (usbi_nfds_t)ctx->event_data_cnt; | 261 | | - int internal_fds, num_ready; | 262 | 262 |
| 263 | 263 | usbi_dbg(ctx, "poll() %u fds with timeout in %dms", (unsigned int)nfds, timeout_ms); | 264 | 264 | #ifdef __EMSCRIPTEN__ | @@ -269,20 +269,21 @@ int usbi_wait_for_events(struct libusb_context *ctx, | 269 | 269 | * in case they ever implement real poll. */ | 270 | 270 | timeout_ms = 0; | 271 | 271 | #endif | 272 | | - num_ready = poll(fds, nfds, timeout_ms); | | 272 | + int num_ready = poll(fds, nfds, timeout_ms); | 273 | 273 | usbi_dbg(ctx, "poll() returned %d", num_ready); | 274 | 274 | if (num_ready == 0) { | 275 | 275 | if (usbi_using_timer(ctx)) | 276 | 276 | goto done; | 277 | 277 | return LIBUSB_ERROR_TIMEOUT; | 278 | | - } else if (num_ready == -1) { | | 278 | + } else if (num_ready < 0) { | 279 | 279 | if (errno == EINTR) | 280 | 280 | return LIBUSB_ERROR_INTERRUPTED; | 281 | 281 | usbi_err(ctx, "poll() failed, errno=%d", errno); | 282 | 282 | return LIBUSB_ERROR_IO; | 283 | 283 | } | 284 | 284 |
| 285 | 285 | /* fds[0] is always the internal signalling event */ | | 286 | + assert(nfds >= 1); | 286 | 287 | if (fds[0].revents) { | 287 | 288 | reported_events->event_triggered = 1; | 288 | 289 | num_ready--; | @@ -292,6 +293,7 @@ int usbi_wait_for_events(struct libusb_context *ctx, | 292 | 293 |
| 293 | 294 | #ifdef HAVE_OS_TIMER | 294 | 295 | /* on timer configurations, fds[1] is the timer */ | | 296 | + assert(usbi_using_timer(ctx) ? (nfds >= 2) : 1); | 295 | 297 | if (usbi_using_timer(ctx) && fds[1].revents) { | 296 | 298 | reported_events->timer_triggered = 1; | 297 | 299 | num_ready--; | @@ -307,7 +309,7 @@ int usbi_wait_for_events(struct libusb_context *ctx, | 307 | 309 | * library's internal file descriptors, so we determine how many are | 308 | 310 | * in use internally for this context and skip these when passing any | 309 | 311 | * remaining pollfds to the backend. */ | 310 | | - internal_fds = usbi_using_timer(ctx) ? 2 : 1; | | 312 | + unsigned int internal_fds = usbi_using_timer(ctx) ? 2 : 1; | 311 | 313 | fds += internal_fds; | 312 | 314 | nfds -= internal_fds; | 313 | 315 |
| @@ -334,13 +336,13 @@ int usbi_wait_for_events(struct libusb_context *ctx, | 334 | 336 | } | 335 | 337 | usbi_mutex_unlock(&ctx->event_data_lock); | 336 | 338 |
| | 339 | + assert(num_ready >= 0); | 337 | 340 | if (num_ready) { | 338 | | - assert(num_ready > 0); | 339 | 341 | reported_events->event_data = fds; | 340 | 342 | reported_events->event_data_count = (unsigned int)nfds; | 341 | 343 | } | 342 | 344 |
| 343 | 345 | done: | 344 | | - reported_events->num_ready = num_ready; | | 346 | + reported_events->num_ready = (unsigned int)num_ready; | 345 | 347 | return LIBUSB_SUCCESS; | 346 | 348 | } |
|