I'm gonna bump the priority of churning through the warnings, else I'm pretty sure they're going to fall through.

Proposed patch attached. Please let me know if still get reports for the ones mentioned below.

On 2012.06.19 19:41, Orin Eman wrote:
..\libusb\core.c(860): warning #188: enumerated type mixed with another type
         ep_type = ep->bmAttributes & 0x3;

Our enum covers the whole range of the AND => safe cast.

..\libusb\core.c(1742): warning #188: enumerated type mixed with another
type
         enum libusb_capability cap = capability;

Not sure why we went through an enum there. And with only one self-referential capability, the function call looks pretty useless as it stands.

Even if we decided to go this way, switching the API call to taking an enum as parameter doesn't look like something we'd want, as someone may be using an old version of the library against newly defined capabilities => might as well drop the intermediate enum variable altogether.

Now, something tells me that someone may have had a reason to cast to an enum first, but none of the toolchains I tested this against seem to complain about the change...

..\libusb\core.c(1886): warning #188: enumerated type mixed with another
type
         enum libusb_error error = error_code;

Likewise. A default statement in the switch should avoid the need for that cast.

..\libusb\os\windows_usb.c(161): warning #181: argument is incompatible
with corresponding format string conversion
         safe_sprintf(err_string, ERR_BUFFER_SIZE, "[%d] ", error_code);

%u obvioulsy, which is safe, as it's used further below.

..\libusb\os\windows_usb.c(2124): warning #111: statement is unreachable
         usbi_dbg("ERROR: broken timer thread");

What statement? ;)

..\libusb\os\windows_usb.c(3519): warning #188: enumerated type mixed
with another type
                       && (HidP_GetValueCaps(j, value_caps, &size[j],
preparsed_data) == HIDP_STATUS_SUCCESS)

Cast is not an issue either, since we're looping along the enum range. I have also made that a bit more explicit in the code.

FWIW, Intel also have a warning level 5... you probably don't want to
see the whining that produces ;)

Not right now, no.

Regards,

/Pete

>From 4ef3550cb8dac0ee1d46a4b9a6f165a1074de4d0 Mon Sep 17 00:00:00 2001
From: Pete Batard <p...@akeo.ie>
Date: Thu, 21 Jun 2012 20:17:09 +0100
Subject: [PATCH] Windows: Fix warnings reported by the Intel Compiler

* windows_usb.c(161): warning #181: argument is incompatible
  with corresponding format string conversion
* windows_usb.c(2124): warning #111: statement is unreachable
  usbi_dbg("ERROR: broken timer thread");
* multiple: warning #188: enumerated type mixed with another
* Issues reported by Orin Eman
---
 libusb/core.c           |   11 +++++------
 libusb/os/windows_usb.c |    7 +++----
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/libusb/core.c b/libusb/core.c
index 1e3edc6..dd352f9 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -857,7 +857,7 @@ int API_EXPORTED 
libusb_get_max_iso_packet_size(libusb_device *dev,
                return LIBUSB_ERROR_NOT_FOUND;
 
        val = ep->wMaxPacketSize;
-       ep_type = ep->bmAttributes & 0x3;
+       ep_type = (enum libusb_transfer_type) (ep->bmAttributes & 0x3);
        libusb_free_config_descriptor(config);
 
        r = val & 0x07ff;
@@ -1739,8 +1739,7 @@ void API_EXPORTED libusb_exit(struct libusb_context *ctx)
  */
 int API_EXPORTED libusb_has_capability(uint32_t capability)
 {
-       enum libusb_capability cap = capability;
-       switch (cap) {
+       switch (capability) {
        case LIBUSB_CAP_HAS_CAPABILITY:
                return 1;
        }
@@ -1883,8 +1882,7 @@ void usbi_log(struct libusb_context *ctx, enum 
usbi_log_level level,
  */
 DEFAULT_VISIBILITY const char * LIBUSB_CALL libusb_error_name(int error_code)
 {
-       enum libusb_error error = error_code;
-       switch (error) {
+       switch (error_code) {
        case LIBUSB_SUCCESS:
                return "LIBUSB_SUCCESS";
        case LIBUSB_ERROR_IO:
@@ -1913,8 +1911,9 @@ DEFAULT_VISIBILITY const char * LIBUSB_CALL 
libusb_error_name(int error_code)
                return "LIBUSB_ERROR_NOT_SUPPORTED";
        case LIBUSB_ERROR_OTHER:
                return "LIBUSB_ERROR_OTHER";
+       default:
+               return "**UNKNOWN**";
        }
-       return "**UNKNOWN**";
 }
 
 /** \ingroup misc
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index 461633b..0e3d309 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -158,7 +158,7 @@ static char err_string[ERR_BUFFER_SIZE];
 
        error_code = retval?retval:GetLastError();
 
-       safe_sprintf(err_string, ERR_BUFFER_SIZE, "[%d] ", error_code);
+       safe_sprintf(err_string, ERR_BUFFER_SIZE, "[%u] ", error_code);
 
        size = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_code,
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
&err_string[safe_strlen(err_string)],
@@ -2121,7 +2121,6 @@ unsigned __stdcall windows_clock_gettime_threaded(void* 
param)
                        return 0;
                }
        }
-       usbi_dbg("ERROR: broken timer thread");
        return 1;
 }
 
@@ -3510,13 +3509,13 @@ static int hid_open(struct libusb_device_handle 
*dev_handle)
                size[0] = capabilities.NumberInputValueCaps;
                size[1] = capabilities.NumberOutputValueCaps;
                size[2] = capabilities.NumberFeatureValueCaps;
-               for (j=0; j<3; j++) {
+               for (j=HidP_Input; j<=HidP_Feature; j++) {
                        usbi_dbg("%d HID %s report value(s) found", size[j], 
type[j]);
                        priv->hid->uses_report_ids[j] = false;
                        if (size[j] > 0) {
                                value_caps = (HIDP_VALUE_CAPS*) calloc(size[j], 
sizeof(HIDP_VALUE_CAPS));
                                if ( (value_caps != NULL)
-                                 && (HidP_GetValueCaps(j, value_caps, 
&size[j], preparsed_data) == HIDP_STATUS_SUCCESS)
+                                 && (HidP_GetValueCaps((HIDP_REPORT_TYPE)j, 
value_caps, &size[j], preparsed_data) == HIDP_STATUS_SUCCESS)
                                  && (size[j] >= 1) ) {
                                        nb_ids[0] = 0;
                                        nb_ids[1] = 0;
-- 
1.7.10.msysgit.1

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to