GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix most remaining Clang -Wsign-conversion warnings · Raghuvardhan-Reddy78/libusb@bc1ddf4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • examples
    • ezusb.c
    • fxload.c
    • sam3u_benchmark.c
    • xusb.c
  • libusb
    • libusb.h
    • os
      • events_posix.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎examples/ezusb.c‎

Copy file name to clipboardExpand all lines: examples/ezusb.c
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,6 @@ static int parse_iic(FILE *image, void *context,
442442
int (*poke)(void *context, uint32_t addr, bool external, const unsigned char *data, size_t len))
443443
{
444444
unsigned char data[4096];
445-
uint32_t data_addr = 0;
446-
size_t data_len = 0, read_len;
447445
uint8_t block_header[4];
448446
int rc;
449447
bool external = false;
@@ -466,14 +464,14 @@ static int parse_iic(FILE *image, void *context,
466464
logerror("unable to read IIC block header\n");
467465
return -1;
468466
}
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]);
471469
if (data_len > sizeof(data)) {
472470
/* If this is ever reported as an error, switch to using malloc/realloc */
473471
logerror("IIC data block too small - please report this error to libusb.info\n");
474472
return -1;
475473
}
476-
read_len = fread(data, 1, data_len, image);
474+
size_t read_len = fread(data, 1, data_len, image);
477475
if (read_len != data_len) {
478476
logerror("read error\n");
479477
return -1;
Collapse file

‎examples/fxload.c‎

Copy file name to clipboardExpand all lines: examples/fxload.c
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ int main(int argc, char*argv[])
9494
const char *ext, *img_name[] = IMG_TYPE_NAMES;
9595
int fx_type = FX_TYPE_UNDEFINED, img_type[ARRAYSIZE(path)];
9696
int opt, status;
97-
unsigned int i, j;
9897
unsigned vid = 0, pid = 0;
9998
unsigned busnum = 0, devaddr = 0, _busnum, _devaddr;
10099
libusb_device *dev, **devs;
@@ -164,6 +163,7 @@ int main(int argc, char*argv[])
164163

165164
/* determine the target type */
166165
if (type != NULL) {
166+
int i;
167167
for (i=0; i<FX_TYPE_MAX; i++) {
168168
if (strcmp(type, fx_name[i]) == 0) {
169169
fx_type = i;
@@ -190,7 +190,7 @@ int main(int argc, char*argv[])
190190
logerror("libusb_get_device_list() failed: %s\n", libusb_error_name(status));
191191
goto err;
192192
}
193-
for (i=0; (dev=devs[i]) != NULL; i++) {
193+
for (unsigned int i=0; (dev=devs[i]) != NULL; i++) {
194194
_busnum = libusb_get_bus_number(dev);
195195
_devaddr = libusb_get_device_address(dev);
196196
if ((type != NULL) && (device_path != NULL)) {
@@ -200,6 +200,7 @@ int main(int argc, char*argv[])
200200
} else {
201201
status = libusb_get_device_descriptor(dev, &desc);
202202
if (status >= 0) {
203+
unsigned int j;
203204
if (verbose >= 3) {
204205
logerror("examining %04x:%04x (%d,%d)\n",
205206
desc.idVendor, desc.idProduct, _busnum, _devaddr);
@@ -265,7 +266,7 @@ int main(int argc, char*argv[])
265266
if (verbose)
266267
logerror("microcontroller type: %s\n", fx_name[fx_type]);
267268

268-
for (i=0; i<ARRAYSIZE(path); i++) {
269+
for (unsigned int i=0; i<ARRAYSIZE(path); i++) {
269270
if (path[i] != NULL) {
270271
ext = path[i] + strlen(path[i]) - 4;
271272
if ((libusb_strcasecmp(ext, ".hex") == 0) || (libusb_strcasecmp(ext, ".ihx") == 0))
Collapse file

‎examples/sam3u_benchmark.c‎

Copy file name to clipboardExpand all lines: examples/sam3u_benchmark.c
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static void LIBUSB_CALL cb_xfr(struct libusb_transfer *xfr)
106106
else
107107
printf(" ");
108108
}
109-
num_bytes += xfr->actual_length;
109+
num_bytes += (unsigned long)xfr->actual_length;
110110
num_xfer++;
111111

112112
if (libusb_submit_transfer(xfr) < 0) {
@@ -133,7 +133,7 @@ static int benchmark_in(uint8_t ep)
133133
if (ep == EP_ISO_IN) {
134134
libusb_fill_iso_transfer(xfr, devh, ep, buf,
135135
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);
137137
} else
138138
libusb_fill_bulk_transfer(xfr, devh, ep, buf,
139139
sizeof(buf), cb_xfr, NULL, 0);
@@ -160,14 +160,12 @@ static int benchmark_in(uint8_t ep)
160160
static void measure(void)
161161
{
162162
struct timeval tv_stop;
163-
unsigned long diff_msec;
164-
165163
get_timestamp(&tv_stop);
166164

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;
168166
diff_msec += (tv_stop.tv_usec - tv_start.tv_usec) / 1000L;
169167

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",
171169
num_xfer, num_bytes, diff_msec, (num_bytes * 1000L) / diff_msec);
172170
}
173171

Collapse file

‎examples/xusb.c‎

Copy file name to clipboardExpand all lines: examples/xusb.c
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ static void perr(char const *format, ...)
7878
#define CALL_CHECK(fcall) do { int _r=fcall; if (_r < 0) ERR_EXIT(_r); } while (0)
7979
#define CALL_CHECK_CLOSE(fcall, hdl) do { int _r=fcall; if (_r < 0) { libusb_close(hdl); ERR_EXIT(_r); } } while (0)
8080
#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])))
8382
#define RETRY_MAX 5
8483
#define REQUEST_SENSE_LENGTH 0x12
8584
#define INQUIRY_LENGTH 0x24
@@ -326,7 +325,7 @@ static int set_xbox_actuators(libusb_device_handle *handle, uint8_t left, uint8_
326325
}
327326

328327
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)
330329
{
331330
static uint32_t tag = 1;
332331
uint8_t cdb_len;
@@ -548,12 +547,12 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in,
548547
cdb[8] = 0x01; // 1 block
549548

550549
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);
552551
printf(" READ: received %d bytes\n", size);
553552
if (get_mass_storage_status(handle, endpoint_in, expected_tag) == -2) {
554553
get_sense(handle, endpoint_in, endpoint_out);
555554
} else {
556-
display_buffer_hex(data, size);
555+
display_buffer_hex(data, (unsigned int)size);
557556
if (binary_dump) {
558557
fd = fopen(binary_name, "w");
559558
if (fd != NULL) {
Collapse file

‎libusb/libusb.h‎

Copy file name to clipboardExpand all lines: libusb/libusb.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ struct libusb_transfer {
15251525

15261526
/** Actual length of data that was transferred. Read-only, and only for
15271527
* use within transfer callback function. Not valid for isochronous
1528-
* endpoint transfers. */
1528+
* endpoint transfers. Never negative. */
15291529
int actual_length;
15301530

15311531
/** Callback function. This will be invoked when the transfer completes,
Collapse file

‎libusb/os/events_posix.c‎

Copy file name to clipboardExpand all lines: libusb/os/events_posix.c
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "libusbi.h"
2525

26+
#include <assert.h>
2627
#include <errno.h>
2728
#include <fcntl.h>
2829
#ifdef HAVE_EVENTFD
@@ -258,7 +259,6 @@ int usbi_wait_for_events(struct libusb_context *ctx,
258259
{
259260
struct pollfd *fds = (struct pollfd *)ctx->event_data;
260261
usbi_nfds_t nfds = (usbi_nfds_t)ctx->event_data_cnt;
261-
int internal_fds, num_ready;
262262

263263
usbi_dbg(ctx, "poll() %u fds with timeout in %dms", (unsigned int)nfds, timeout_ms);
264264
#ifdef __EMSCRIPTEN__
@@ -269,20 +269,21 @@ int usbi_wait_for_events(struct libusb_context *ctx,
269269
* in case they ever implement real poll. */
270270
timeout_ms = 0;
271271
#endif
272-
num_ready = poll(fds, nfds, timeout_ms);
272+
int num_ready = poll(fds, nfds, timeout_ms);
273273
usbi_dbg(ctx, "poll() returned %d", num_ready);
274274
if (num_ready == 0) {
275275
if (usbi_using_timer(ctx))
276276
goto done;
277277
return LIBUSB_ERROR_TIMEOUT;
278-
} else if (num_ready == -1) {
278+
} else if (num_ready < 0) {
279279
if (errno == EINTR)
280280
return LIBUSB_ERROR_INTERRUPTED;
281281
usbi_err(ctx, "poll() failed, errno=%d", errno);
282282
return LIBUSB_ERROR_IO;
283283
}
284284

285285
/* fds[0] is always the internal signalling event */
286+
assert(nfds >= 1);
286287
if (fds[0].revents) {
287288
reported_events->event_triggered = 1;
288289
num_ready--;
@@ -292,6 +293,7 @@ int usbi_wait_for_events(struct libusb_context *ctx,
292293

293294
#ifdef HAVE_OS_TIMER
294295
/* on timer configurations, fds[1] is the timer */
296+
assert(usbi_using_timer(ctx) ? (nfds >= 2) : 1);
295297
if (usbi_using_timer(ctx) && fds[1].revents) {
296298
reported_events->timer_triggered = 1;
297299
num_ready--;
@@ -307,7 +309,7 @@ int usbi_wait_for_events(struct libusb_context *ctx,
307309
* library's internal file descriptors, so we determine how many are
308310
* in use internally for this context and skip these when passing any
309311
* 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;
311313
fds += internal_fds;
312314
nfds -= internal_fds;
313315

@@ -334,13 +336,13 @@ int usbi_wait_for_events(struct libusb_context *ctx,
334336
}
335337
usbi_mutex_unlock(&ctx->event_data_lock);
336338

339+
assert(num_ready >= 0);
337340
if (num_ready) {
338-
assert(num_ready > 0);
339341
reported_events->event_data = fds;
340342
reported_events->event_data_count = (unsigned int)nfds;
341343
}
342344

343345
done:
344-
reported_events->num_ready = num_ready;
346+
reported_events->num_ready = (unsigned int)num_ready;
345347
return LIBUSB_SUCCESS;
346348
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.