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 — Fixed many compiler warnings about sign and size mismatch · Raghuvardhan-Reddy78/libusb@8a05a3f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Xcode
    • common.xcconfig
  • examples
    • ezusb.c
    • sam3u_benchmark.c
    • xusb.c
  • libusb
    • core.c
    • descriptor.c
    • hotplug.h
    • io.c
    • libusb.h
    • libusbi.h
    • os
      • darwin_usb.c
      • darwin_usb.h
      • haiku_usb_backend.cpp
    • version_nano.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Xcode/common.xcconfig‎

Copy file name to clipboardExpand all lines: Xcode/common.xcconfig
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,21 @@ GCC_WARN_UNKNOWN_PRAGMAS = YES
3737
GCC_WARN_UNUSED_FUNCTION = YES
3838
GCC_WARN_UNUSED_LABEL = YES
3939
GCC_WARN_UNUSED_VARIABLE = YES
40+
GCC_WARN_UNUSED_PARAMETER = YES
4041
CLANG_WARN_EMPTY_BODY = YES
4142
CLANG_WARN_CONSTANT_CONVERSION = YES
4243
CLANG_WARN_ENUM_CONVERSION = YES
4344
CLANG_WARN_INT_CONVERSION = YES
4445
CLANG_WARN_DOCUMENTATION_COMMENTS = YES
4546
CLANG_WARN_BOOL_CONVERSION = YES
47+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES
48+
CLANG_WARN_FLOAT_CONVERSION = YES
49+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES
50+
CLANG_WARN_INFINITE_RECURSION = YES
51+
CLANG_WARN_ASSIGN_ENUM = YES
52+
CLANG_WARN_STRICT_PROTOTYPES = YES
53+
CLANG_WARN_COMMA = YES
54+
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES
4655

4756
// Static analyzer warnings.
4857
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES
Collapse file

‎examples/ezusb.c‎

Copy file name to clipboardExpand all lines: examples/ezusb.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ static int parse_ihex(FILE *image, void *context,
299299
/* Read the target offset (address up to 64KB) */
300300
tmp = buf[7];
301301
buf[7] = 0;
302-
off = (int)strtoul(buf+3, NULL, 16);
302+
off = (unsigned int)strtoul(buf+3, NULL, 16);
303303
buf[7] = tmp;
304304

305305
/* Initialize data_addr */
Collapse file

‎examples/sam3u_benchmark.c‎

Copy file name to clipboardExpand all lines: examples/sam3u_benchmark.c
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ static void LIBUSB_CALL cb_xfr(struct libusb_transfer *xfr)
5555
struct libusb_iso_packet_descriptor *pack = &xfr->iso_packet_desc[i];
5656

5757
if (pack->status != LIBUSB_TRANSFER_COMPLETED) {
58-
fprintf(stderr, "Error: pack %u status %d\n", i, pack->status);
58+
fprintf(stderr, "Error: pack %d status %d\n", i, pack->status);
5959
exit(5);
6060
}
6161

62-
printf("pack%u length:%u, actual_length:%u\n", i, pack->length, pack->actual_length);
62+
printf("pack%d length:%u, actual_length:%u\n", i, pack->length, pack->actual_length);
6363
}
6464
}
6565

Collapse file

‎examples/xusb.c‎

Copy file name to clipboardExpand all lines: examples/xusb.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in)
627627
}
628628
display_buffer_hex(hid_report_descriptor, descriptor_size);
629629
if ((binary_dump) && ((fd = fopen(binary_name, "w")) != NULL)) {
630-
if (fwrite(hid_report_descriptor, 1, descriptor_size, fd) != descriptor_size) {
630+
if (fwrite(hid_report_descriptor, 1, descriptor_size, fd) != (size_t)descriptor_size) {
631631
printf(" Error writing descriptor to file\n");
632632
}
633633
fclose(fd);
Collapse file

‎libusb/core.c‎

Copy file name to clipboardExpand all lines: libusb/core.c
+14-14Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,8 @@ ssize_t API_EXPORTED libusb_get_device_list(libusb_context *ctx,
845845
}
846846

847847
/* convert discovered_devs into a list */
848-
len = discdevs->len;
849-
ret = calloc(len + 1, sizeof(struct libusb_device *));
848+
len = (ssize_t)discdevs->len;
849+
ret = calloc((size_t)len + 1, sizeof(struct libusb_device *));
850850
if (!ret) {
851851
len = LIBUSB_ERROR_NO_MEM;
852852
goto out;
@@ -1680,12 +1680,12 @@ int API_EXPORTED libusb_claim_interface(libusb_device_handle *dev_handle,
16801680
return LIBUSB_ERROR_NO_DEVICE;
16811681

16821682
usbi_mutex_lock(&dev_handle->lock);
1683-
if (dev_handle->claimed_interfaces & (1 << interface_number))
1683+
if (dev_handle->claimed_interfaces & (1U << interface_number))
16841684
goto out;
16851685

16861686
r = usbi_backend.claim_interface(dev_handle, interface_number);
16871687
if (r == 0)
1688-
dev_handle->claimed_interfaces |= 1 << interface_number;
1688+
dev_handle->claimed_interfaces |= 1U << interface_number;
16891689

16901690
out:
16911691
usbi_mutex_unlock(&dev_handle->lock);
@@ -1721,14 +1721,14 @@ int API_EXPORTED libusb_release_interface(libusb_device_handle *dev_handle,
17211721
return LIBUSB_ERROR_INVALID_PARAM;
17221722

17231723
usbi_mutex_lock(&dev_handle->lock);
1724-
if (!(dev_handle->claimed_interfaces & (1 << interface_number))) {
1724+
if (!(dev_handle->claimed_interfaces & (1U << interface_number))) {
17251725
r = LIBUSB_ERROR_NOT_FOUND;
17261726
goto out;
17271727
}
17281728

17291729
r = usbi_backend.release_interface(dev_handle, interface_number);
17301730
if (r == 0)
1731-
dev_handle->claimed_interfaces &= ~(1 << interface_number);
1731+
dev_handle->claimed_interfaces &= ~(1U << interface_number);
17321732

17331733
out:
17341734
usbi_mutex_unlock(&dev_handle->lock);
@@ -1770,7 +1770,7 @@ int API_EXPORTED libusb_set_interface_alt_setting(libusb_device_handle *dev_hand
17701770
return LIBUSB_ERROR_NO_DEVICE;
17711771
}
17721772

1773-
if (!(dev_handle->claimed_interfaces & (1 << interface_number))) {
1773+
if (!(dev_handle->claimed_interfaces & (1U << interface_number))) {
17741774
usbi_mutex_unlock(&dev_handle->lock);
17751775
return LIBUSB_ERROR_NOT_FOUND;
17761776
}
@@ -2507,7 +2507,7 @@ static void usbi_log_str(enum libusb_log_level level, const char *str)
25072507
case LIBUSB_LOG_LEVEL_DEBUG: syslog_level = LOG_DEBUG; break;
25082508
}
25092509
syslog(syslog_level, "%s", str);
2510-
#else /* All of gcc, Clang, XCode seem to use #warning */
2510+
#else /* All of gcc, Clang, Xcode seem to use #warning */
25112511
#warning System logging is not supported on this platform. Logging to stderr will be used instead.
25122512
fputs(str, stderr);
25132513
#endif
@@ -2589,8 +2589,8 @@ void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
25892589

25902590
if (global_debug) {
25912591
header_len = snprintf(buf, sizeof(buf),
2592-
"[%2d.%06d] [%08x] libusb: %s [%s] ",
2593-
(int)now.tv_sec, (int)(now.tv_nsec / 1000L), usbi_get_tid(), prefix, function);
2592+
"[%2ld.%06ld] [%08x] libusb: %s [%s] ",
2593+
(long)now.tv_sec, (long)(now.tv_nsec / 1000L), usbi_get_tid(), prefix, function);
25942594
} else {
25952595
header_len = snprintf(buf, sizeof(buf),
25962596
"libusb: %s [%s] ", prefix, function);
@@ -2603,16 +2603,16 @@ void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
26032603
}
26042604
/* Make sure buffer is NUL terminated */
26052605
buf[header_len] = '\0';
2606-
text_len = vsnprintf(buf + header_len, sizeof(buf) - header_len,
2606+
text_len = vsnprintf(buf + header_len, sizeof(buf) - (size_t)header_len,
26072607
format, args);
26082608
if (text_len < 0 || text_len + header_len >= (int)sizeof(buf)) {
26092609
/* Truncated log output. On some platforms a -1 return value means
26102610
* that the output was truncated. */
2611-
text_len = sizeof(buf) - header_len;
2611+
text_len = (int)sizeof(buf) - header_len;
26122612
}
2613-
if (header_len + text_len + sizeof(USBI_LOG_LINE_END) >= sizeof(buf)) {
2613+
if (header_len + text_len + (int)sizeof(USBI_LOG_LINE_END) >= (int)sizeof(buf)) {
26142614
/* Need to truncate the text slightly to fit on the terminator. */
2615-
text_len -= (header_len + text_len + sizeof(USBI_LOG_LINE_END)) - sizeof(buf);
2615+
text_len -= (header_len + text_len + (int)sizeof(USBI_LOG_LINE_END)) - (int)sizeof(buf);
26162616
}
26172617
strcpy(buf + header_len + text_len, USBI_LOG_LINE_END);
26182618

Collapse file

‎libusb/descriptor.c‎

Copy file name to clipboardExpand all lines: libusb/descriptor.c
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int usbi_parse_descriptor(const unsigned char *source, const char *descriptor,
6262
if (host_endian) {
6363
memcpy(dp, sp, 2);
6464
} else {
65-
w = (sp[1] << 8) | sp[0];
65+
w = (uint16_t)((sp[1] << 8) | sp[0]);
6666
*((uint16_t *)dp) = w;
6767
}
6868
sp += 2;
@@ -74,8 +74,8 @@ int usbi_parse_descriptor(const unsigned char *source, const char *descriptor,
7474
if (host_endian) {
7575
memcpy(dp, sp, 4);
7676
} else {
77-
d = (sp[3] << 24) | (sp[2] << 16) |
78-
(sp[1] << 8) | sp[0];
77+
d = (uint32_t)((sp[3] << 24) | (sp[2] << 16) |
78+
(sp[1] << 8) | sp[0]);
7979
*((uint32_t *)dp) = d;
8080
}
8181
sp += 4;
@@ -168,13 +168,13 @@ static int parse_endpoint(struct libusb_context *ctx,
168168
/* Copy any unknown descriptors into a storage area for drivers */
169169
/* to later parse */
170170
len = (int)(buffer - begin);
171-
if (!len) {
171+
if (len <= 0) {
172172
endpoint->extra = NULL;
173173
endpoint->extra_length = 0;
174174
return parsed;
175175
}
176176

177-
extra = malloc(len);
177+
extra = malloc((size_t)len);
178178
endpoint->extra = extra;
179179
if (!extra) {
180180
endpoint->extra_length = 0;
@@ -230,7 +230,7 @@ static int parse_interface(libusb_context *ctx,
230230
(struct libusb_interface_descriptor *) usb_interface->altsetting;
231231
altsetting = usbi_reallocf(altsetting,
232232
sizeof(struct libusb_interface_descriptor) *
233-
(usb_interface->num_altsetting + 1));
233+
((size_t)usb_interface->num_altsetting + 1));
234234
if (!altsetting) {
235235
r = LIBUSB_ERROR_NO_MEM;
236236
goto err;
@@ -307,8 +307,8 @@ static int parse_interface(libusb_context *ctx,
307307
/* Copy any unknown descriptors into a storage area for */
308308
/* drivers to later parse */
309309
len = (int)(buffer - begin);
310-
if (len) {
311-
ifp->extra = malloc(len);
310+
if (len > 0) {
311+
ifp->extra = malloc((size_t)len);
312312
if (!ifp->extra) {
313313
r = LIBUSB_ERROR_NO_MEM;
314314
goto err;
@@ -453,10 +453,10 @@ static int parse_configuration(struct libusb_context *ctx,
453453
/* Copy any unknown descriptors into a storage area for */
454454
/* drivers to later parse */
455455
len = (int)(buffer - begin);
456-
if (len) {
456+
if (len > 0) {
457457
/* FIXME: We should realloc and append here */
458458
if (!config->extra_length) {
459-
config->extra = malloc(len);
459+
config->extra = malloc((size_t)len);
460460
if (!config->extra) {
461461
r = LIBUSB_ERROR_NO_MEM;
462462
goto err;
@@ -1163,7 +1163,7 @@ int API_EXPORTED libusb_get_string_descriptor_ascii(libusb_device_handle *dev_ha
11631163
if (r < 4)
11641164
return LIBUSB_ERROR_IO;
11651165

1166-
langid = tbuf[2] | (tbuf[3] << 8);
1166+
langid = (uint16_t)(tbuf[2] | (tbuf[3] << 8));
11671167

11681168
r = libusb_get_string_descriptor(dev_handle, desc_index, langid, tbuf,
11691169
sizeof(tbuf));
Collapse file

‎libusb/hotplug.h‎

Copy file name to clipboardExpand all lines: libusb/hotplug.h
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ enum usbi_hotplug_flags {
3636
*/
3737

3838
/* The vendor_id field is valid for matching */
39-
USBI_HOTPLUG_VENDOR_ID_VALID = (1 << 3),
39+
USBI_HOTPLUG_VENDOR_ID_VALID = (1U << 3),
4040

4141
/* The product_id field is valid for matching */
42-
USBI_HOTPLUG_PRODUCT_ID_VALID = (1 << 4),
42+
USBI_HOTPLUG_PRODUCT_ID_VALID = (1U << 4),
4343

4444
/* The dev_class field is valid for matching */
45-
USBI_HOTPLUG_DEV_CLASS_VALID = (1 << 5),
45+
USBI_HOTPLUG_DEV_CLASS_VALID = (1U << 5),
4646

4747
/* This callback has been unregistered and needs to be freed */
48-
USBI_HOTPLUG_NEEDS_FREE = (1 << 6),
48+
USBI_HOTPLUG_NEEDS_FREE = (1U << 6),
4949
};
5050

5151
/** \ingroup hotplug
Collapse file

‎libusb/io.c‎

Copy file name to clipboardExpand all lines: libusb/io.c
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,20 +1248,26 @@ static int calculate_timeout(struct usbi_transfer *transfer)
12481248
* use it on a non-isochronous endpoint. If you do this, ensure that at time
12491249
* of submission, num_iso_packets is 0 and that type is set appropriately.
12501250
*
1251-
* \param iso_packets number of isochronous packet descriptors to allocate
1251+
* \param iso_packets number of isochronous packet descriptors to allocate. Must be non-negative.
12521252
* \returns a newly allocated transfer, or NULL on error
12531253
*/
12541254
DEFAULT_VISIBILITY
12551255
struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(
12561256
int iso_packets)
12571257
{
12581258
struct libusb_transfer *transfer;
1259-
size_t os_alloc_size = usbi_backend.transfer_priv_size;
1260-
size_t alloc_size = sizeof(struct usbi_transfer)
1259+
size_t os_alloc_size;
1260+
size_t alloc_size;
1261+
struct usbi_transfer *itransfer;
1262+
1263+
assert(iso_packets >= 0);
1264+
1265+
os_alloc_size = usbi_backend.transfer_priv_size;
1266+
alloc_size = sizeof(struct usbi_transfer)
12611267
+ sizeof(struct libusb_transfer)
1262-
+ (sizeof(struct libusb_iso_packet_descriptor) * iso_packets)
1268+
+ (sizeof(struct libusb_iso_packet_descriptor) * (size_t)iso_packets)
12631269
+ os_alloc_size;
1264-
struct usbi_transfer *itransfer = calloc(1, alloc_size);
1270+
itransfer = calloc(1, alloc_size);
12651271
if (!itransfer)
12661272
return NULL;
12671273

Collapse file

‎libusb/libusb.h‎

Copy file name to clipboardExpand all lines: libusb/libusb.h
+15-14Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ struct libusb_endpoint_descriptor {
577577
* it will store them here, should you wish to parse them. */
578578
const unsigned char *extra;
579579

580-
/** Length of the extra descriptors, in bytes. */
580+
/** Length of the extra descriptors, in bytes. Must be non-negative. */
581581
int extra_length;
582582
};
583583

@@ -627,7 +627,7 @@ struct libusb_interface_descriptor {
627627
* it will store them here, should you wish to parse them. */
628628
const unsigned char *extra;
629629

630-
/** Length of the extra descriptors, in bytes. */
630+
/** Length of the extra descriptors, in bytes. Must be non-negative. */
631631
int extra_length;
632632
};
633633

@@ -639,7 +639,8 @@ struct libusb_interface {
639639
* by the num_altsetting field. */
640640
const struct libusb_interface_descriptor *altsetting;
641641

642-
/** The number of alternate settings that belong to this interface */
642+
/** The number of alternate settings that belong to this interface.
643+
* Must be non-negative. */
643644
int num_altsetting;
644645
};
645646

@@ -686,7 +687,7 @@ struct libusb_config_descriptor {
686687
* descriptors, it will store them here, should you wish to parse them. */
687688
const unsigned char *extra;
688689

689-
/** Length of the extra descriptors, in bytes. */
690+
/** Length of the extra descriptors, in bytes. Must be non-negative. */
690691
int extra_length;
691692
};
692693

@@ -1134,19 +1135,19 @@ enum libusb_transfer_status {
11341135
* libusb_transfer.flags values */
11351136
enum libusb_transfer_flags {
11361137
/** Report short frames as errors */
1137-
LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
1138+
LIBUSB_TRANSFER_SHORT_NOT_OK = 1U << 0,
11381139

11391140
/** Automatically free() transfer buffer during libusb_free_transfer().
11401141
* Note that buffers allocated with libusb_dev_mem_alloc() should not
11411142
* be attempted freed in this way, since free() is not an appropriate
11421143
* way to release such memory. */
1143-
LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
1144+
LIBUSB_TRANSFER_FREE_BUFFER = 1U << 1,
11441145

11451146
/** Automatically call libusb_free_transfer() after callback returns.
11461147
* If this flag is set, it is illegal to call libusb_free_transfer()
11471148
* from your transfer callback, as this will result in a double-free
11481149
* when this flag is acted upon. */
1149-
LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
1150+
LIBUSB_TRANSFER_FREE_TRANSFER = 1U << 2,
11501151

11511152
/** Terminate transfers that are a multiple of the endpoint's
11521153
* wMaxPacketSize with an extra zero length packet. This is useful
@@ -1171,7 +1172,7 @@ enum libusb_transfer_flags {
11711172
*
11721173
* Available since libusb-1.0.9.
11731174
*/
1174-
LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3,
1175+
LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1U << 3,
11751176
};
11761177

11771178
/** \ingroup libusb_asyncio
@@ -1232,7 +1233,7 @@ struct libusb_transfer {
12321233
* to determine if errors occurred. */
12331234
enum libusb_transfer_status status;
12341235

1235-
/** Length of the data buffer */
1236+
/** Length of the data buffer. Must be non-negative. */
12361237
int length;
12371238

12381239
/** Actual length of data that was transferred. Read-only, and only for
@@ -1251,7 +1252,7 @@ struct libusb_transfer {
12511252
unsigned char *buffer;
12521253

12531254
/** Number of isochronous packets. Only used for I/O with isochronous
1254-
* endpoints. */
1255+
* endpoints. Must be non-negative. */
12551256
int num_iso_packets;
12561257

12571258
/** Isochronous packet descriptors, for isochronous transfers only. */
@@ -1910,10 +1911,10 @@ typedef int libusb_hotplug_callback_handle;
19101911
* Flags for hotplug events */
19111912
typedef enum {
19121913
/** Default value when not using any flags. */
1913-
LIBUSB_HOTPLUG_NO_FLAGS = 0,
1914+
LIBUSB_HOTPLUG_NO_FLAGS = 0U,
19141915

19151916
/** Arm the callback and fire it for all matching currently attached devices. */
1916-
LIBUSB_HOTPLUG_ENUMERATE = 1<<0,
1917+
LIBUSB_HOTPLUG_ENUMERATE = 1U << 0,
19171918
} libusb_hotplug_flag;
19181919

19191920
/** \ingroup libusb_hotplug
@@ -1923,12 +1924,12 @@ typedef enum {
19231924
* Hotplug events */
19241925
typedef enum {
19251926
/** A device has been plugged in and is ready to use */
1926-
LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01,
1927+
LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01U,
19271928

19281929
/** A device has left and is no longer available.
19291930
* It is the user's responsibility to call libusb_close on any handle associated with a disconnected device.
19301931
* It is safe to call libusb_get_device_descriptor on a device that has left */
1931-
LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02,
1932+
LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02U,
19321933
} libusb_hotplug_event;
19331934

19341935
/** \ingroup libusb_hotplug

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.