aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2020-11-09 15:51:44 -0800
committerChris Dickens <christopher.a.dickens@gmail.com>2020-11-09 15:51:44 -0800
commit15668087a743dced7a917ce448b6e1c2eeb48b95 (patch)
treefd4914e09d16c43b2247113196ce7b474c409d36
parentab5dcf4f44b344500adfaf0a676eb0649fdb5d34 (diff)
downloadlibusb-15668087a743dced7a917ce448b6e1c2eeb48b95.tar.gz
Fix various CI build warnings
* [-Wpointer-arith] arithmetic on a pointer to void is a GNU extension * [-Wswitch-enum] enumeration values 'E1, ...' not explicitly handled in switch * [-Wunused-parameter] unused parameter 'p' For '-Wswitch-enum', the switch statements in the individual backends' set_option() function has been removed. It is not expected that backends will need to handle or be aware of all the options. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rwxr-xr-xexamples/testlibusb.c1
-rw-r--r--libusb/core.c4
-rw-r--r--libusb/os/linux_usbfs.c27
-rw-r--r--libusb/os/windows_common.c14
-rw-r--r--libusb/os/windows_winusb.c12
-rw-r--r--libusb/version_nano.h2
6 files changed, 35 insertions, 25 deletions
diff --git a/examples/testlibusb.c b/examples/testlibusb.c
index 52bf501..ba00f90 100755
--- a/examples/testlibusb.c
+++ b/examples/testlibusb.c
@@ -261,6 +261,7 @@ static int test_wrapped_device(const char *device_name)
#else
static int test_wrapped_device(const char *device_name)
{
+ (void)device_name;
printf("Testing wrapped devices is not supported on your platform\n");
return 1;
}
diff --git a/libusb/core.c b/libusb/core.c
index a6b093b..07d459c 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -2524,6 +2524,7 @@ static void log_str(enum libusb_log_level level, const char *str)
#if defined(__ANDROID__)
int priority;
switch (level) {
+ case LIBUSB_LOG_LEVEL_NONE: return; /* Impossible, but keeps compiler happy */
case LIBUSB_LOG_LEVEL_ERROR: priority = ANDROID_LOG_ERROR; break;
case LIBUSB_LOG_LEVEL_WARNING: priority = ANDROID_LOG_WARN; break;
case LIBUSB_LOG_LEVEL_INFO: priority = ANDROID_LOG_INFO; break;
@@ -2537,6 +2538,7 @@ static void log_str(enum libusb_log_level level, const char *str)
#elif defined(HAVE_SYSLOG)
int syslog_level;
switch (level) {
+ case LIBUSB_LOG_LEVEL_NONE: return; /* Impossible, but keeps compiler happy */
case LIBUSB_LOG_LEVEL_ERROR: syslog_level = LOG_ERR; break;
case LIBUSB_LOG_LEVEL_WARNING: syslog_level = LOG_WARNING; break;
case LIBUSB_LOG_LEVEL_INFO: syslog_level = LOG_INFO; break;
@@ -2585,6 +2587,8 @@ static void log_v(struct libusb_context *ctx, enum libusb_log_level level,
#endif
switch (level) {
+ case LIBUSB_LOG_LEVEL_NONE: /* Impossible, but keeps compiler happy */
+ return;
case LIBUSB_LOG_LEVEL_ERROR:
prefix = "error";
break;
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index f3c188e..fb2ed53 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -429,16 +429,17 @@ static int op_set_option(struct libusb_context *ctx, enum libusb_option option,
UNUSED(ctx);
UNUSED(ap);
- switch (option) {
#ifdef __ANDROID__
- case LIBUSB_OPTION_WEAK_AUTHORITY:
+ if (option == LIBUSB_OPTION_WEAK_AUTHORITY) {
usbi_dbg("set libusb has weak authority");
weak_authority = 1;
return LIBUSB_SUCCESS;
-#endif
- default:
- return LIBUSB_ERROR_NOT_SUPPORTED;
}
+#else
+ UNUSED(option);
+#endif
+
+ return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int linux_scan_devices(struct libusb_context *ctx)
@@ -676,7 +677,7 @@ static int parse_config_descriptors(struct libusb_device *dev)
uint8_t *buffer;
size_t remaining;
- device_desc = (struct usbi_device_descriptor *)priv->descriptors;
+ device_desc = priv->descriptors;
num_configs = device_desc->bNumConfigurations;
if (num_configs == 0)
@@ -686,7 +687,7 @@ static int parse_config_descriptors(struct libusb_device *dev)
if (!priv->config_descriptors)
return LIBUSB_ERROR_NO_MEM;
- buffer = priv->descriptors + LIBUSB_DT_DEVICE_SIZE;
+ buffer = (uint8_t *)priv->descriptors + LIBUSB_DT_DEVICE_SIZE;
remaining = priv->descriptors_len - LIBUSB_DT_DEVICE_SIZE;
for (idx = 0; idx < num_configs; idx++) {
@@ -935,19 +936,21 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
alloc_len = 0;
do {
- alloc_len += 256;
+ const size_t desc_read_length = 256;
+ uint8_t *read_ptr;
+
+ alloc_len += desc_read_length;
priv->descriptors = usbi_reallocf(priv->descriptors, alloc_len);
if (!priv->descriptors) {
if (fd != wrapped_fd)
close(fd);
return LIBUSB_ERROR_NO_MEM;
}
+ read_ptr = (uint8_t *)priv->descriptors + priv->descriptors_len;
/* usbfs has holes in the file */
if (!sysfs_dir)
- memset(priv->descriptors + priv->descriptors_len,
- 0, alloc_len - priv->descriptors_len);
- nb = read(fd, priv->descriptors + priv->descriptors_len,
- alloc_len - priv->descriptors_len);
+ memset(read_ptr, 0, desc_read_length);
+ nb = read(fd, read_ptr, desc_read_length);
if (nb < 0) {
usbi_err(ctx, "read descriptor failed, errno=%d", errno);
if (fd != wrapped_fd)
diff --git a/libusb/os/windows_common.c b/libusb/os/windows_common.c
index 8dc0e0a..f25c340 100644
--- a/libusb/os/windows_common.c
+++ b/libusb/os/windows_common.c
@@ -592,19 +592,17 @@ static int windows_set_option(struct libusb_context *ctx, enum libusb_option opt
UNUSED(ap);
- switch ((int)option) {
- case LIBUSB_OPTION_USE_USBDK:
- if (usbdk_available) {
- usbi_dbg("switching context %p to use UsbDk backend", ctx);
- priv->backend = &usbdk_backend;
- } else {
+ if (option == LIBUSB_OPTION_USE_USBDK) {
+ if (!usbdk_available) {
usbi_err(ctx, "UsbDk backend not available");
return LIBUSB_ERROR_NOT_FOUND;
}
+ usbi_dbg("switching context %p to use UsbDk backend", ctx);
+ priv->backend = &usbdk_backend;
return LIBUSB_SUCCESS;
- default:
- return LIBUSB_ERROR_NOT_SUPPORTED;
}
+
+ return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int windows_get_device_list(struct libusb_context *ctx, struct discovered_devs **discdevs)
diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c
index 0f857ed..e0d7b1f 100644
--- a/libusb/os/windows_winusb.c
+++ b/libusb/os/windows_winusb.c
@@ -982,14 +982,18 @@ make_descriptors:
config_desc_length = ROOT_HUB_HS_CONFIG_DESC_LENGTH;
ep_interval = 0x0c; // 256ms
break;
- default:
- // The default case means absolutely no information about this root hub was
- // determined. There is not much choice than to be pessimistic and label this
- // as a full-speed device.
+ case LIBUSB_SPEED_LOW: // Not used, but keeps compiler happy
+ case LIBUSB_SPEED_UNKNOWN:
+ // This case means absolutely no information about this root hub was determined.
+ // There is not much choice than to be pessimistic and label this as a
+ // full-speed device.
speed = LIBUSB_SPEED_FULL;
+ // fallthrough
+ case LIBUSB_SPEED_FULL:
dev->device_descriptor.bcdUSB = 0x0110;
config_desc_length = ROOT_HUB_FS_CONFIG_DESC_LENGTH;
ep_interval = 0xff; // 255ms
+ break;
}
if (speed >= LIBUSB_SPEED_SUPER) {
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 9c3a26e..d853d67 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11572
+#define LIBUSB_NANO 11573