Fix various CI build warnings
authorChris Dickens <christopher.a.dickens@gmail.com>
Mon, 9 Nov 2020 23:51:44 +0000 (15:51 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Mon, 9 Nov 2020 23:51:44 +0000 (15:51 -0800)
  * [-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>
examples/testlibusb.c
libusb/core.c
libusb/os/linux_usbfs.c
libusb/os/windows_common.c
libusb/os/windows_winusb.c
libusb/version_nano.h

index 52bf5011055be2075561432768cb4dd92f4e43e0..ba00f9061b2874d9e29c57b5116e1ca8c3e22e22 100755 (executable)
@@ -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;
 }
index a6b093ba783a39e1edca7a60aa31607df70d615f..07d459c1269c64b39ce2e83b59bec9a3fd9626ab 100644 (file)
@@ -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;
index f3c188e604eb5138e8dd31ba683738930b6df12a..fb2ed53a9ed02cdaff5cf3a38577d38c8eb0e54b 100644 (file)
@@ -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)
index 8dc0e0a536aa7473382c9f30b223059b1584def4..f25c34051a2873d0dafa05344911fac5b5a6e341 100644 (file)
@@ -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)
index 0f857ed58bf7c296a3771029df7575063a80b1ee..e0d7b1fff9ced663bbb648c5d1ec975437c96900 100644 (file)
@@ -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) {
index 9c3a26e07af24a7ce5e42b7641af3d9cb98a9705..d853d672e700267031fcbe515146b7e85dc4cd12 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11572
+#define LIBUSB_NANO 11573