Fixed various trivial cppcheck 1.80 warnings
authorSean McBride <sean@rogue-research.com>
Thu, 28 Dec 2017 04:53:27 +0000 (23:53 -0500)
committerChris Dickens <christopher.a.dickens@gmail.com>
Fri, 29 Dec 2017 06:40:30 +0000 (22:40 -0800)
Specifically:

redundantAssignment,examples/dpfp.c:422,style,Variable 'r' is reassigned a value before the old one has been used.
redundantAssignment,libusb/os/threads_posix.c:64,style,Variable 'ret' is reassigned a value before the old one has been used.
unreadVariable,libusb/os/netbsd_usb.c:217,style,Variable 'hpriv' is assigned a value that is never used.
unreadVariable,libusb/os/netbsd_usb.c:235,style,Variable 'hpriv' is assigned a value that is never used.
unreadVariable,libusb/os/openbsd_usb.c:251,style,Variable 'hpriv' is assigned a value that is never used.
unreadVariable,libusb/os/openbsd_usb.c:275,style,Variable 'hpriv' is assigned a value that is never used.
unsignedLessThanZero,libusb/os/windows_winusb.c:259,style,Checking if unsigned variable '_index' is less than zero.
unsignedLessThanZero,libusb/os/windows_winusb.c:298,style,Checking if unsigned variable '_index' is less than zero.
unsignedLessThanZero,libusb/os/windows_winusb.c:367,style,Checking if unsigned variable '_index' is less than zero.
invalidPrintfArgType_sint,examples/xusb.c:534,warning,%d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
examples/dpfp.c
examples/xusb.c
libusb/os/netbsd_usb.c
libusb/os/openbsd_usb.c
libusb/os/threads_posix.c
libusb/os/windows_winusb.c
libusb/version_nano.h

index b23a8fc..77f9476 100644 (file)
@@ -419,7 +419,7 @@ static void sighandler(int signum)
 int main(void)
 {
        struct sigaction sigact;
-       int r = 1;
+       int r;
 
        r = libusb_init(NULL);
        if (r < 0) {
index e852292..4ac11b8 100644 (file)
@@ -531,7 +531,7 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in,
        }
 
        // Send Read
-       printf("Attempting to read %d bytes:\n", block_size);
+       printf("Attempting to read %u bytes:\n", block_size);
        memset(cdb, 0, sizeof(cdb));
 
        cdb[0] = 0x28;  // Read(10)
index 8f9fa36..d9c059a 100644 (file)
@@ -214,7 +214,6 @@ error:
 int
 netbsd_open(struct libusb_device_handle *handle)
 {
-       struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
        struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
 
        dpriv->fd = open(dpriv->devnode, O_RDWR);
@@ -232,7 +231,6 @@ netbsd_open(struct libusb_device_handle *handle)
 void
 netbsd_close(struct libusb_device_handle *handle)
 {
-       struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
        struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
 
        usbi_dbg("close: fd %d", dpriv->fd);
index ac770f4..f174e49 100644 (file)
@@ -248,7 +248,6 @@ obsd_get_device_list(struct libusb_context * ctx,
 int
 obsd_open(struct libusb_device_handle *handle)
 {
-       struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
        struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
        char devnode[16];
 
@@ -272,7 +271,6 @@ obsd_open(struct libusb_device_handle *handle)
 void
 obsd_close(struct libusb_device_handle *handle)
 {
-       struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
        struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
 
        if (dpriv->devname) {
index 2d580c3..ce14445 100644 (file)
@@ -59,7 +59,7 @@ int usbi_cond_timedwait(pthread_cond_t *cond,
 
 int usbi_get_tid(void)
 {
-       int ret = -1;
+       int ret;
 #if defined(__ANDROID__)
        ret = gettid();
 #elif defined(__linux__)
@@ -73,6 +73,8 @@ int usbi_get_tid(void)
        mach_port_deallocate(mach_task_self(), ret);
 #elif defined(__CYGWIN__)
        ret = GetCurrentThreadId();
+#else
+       ret = -1;
 #endif
 /* TODO: NetBSD thread ID support */
        return ret;
index 6ec5f70..05a360e 100644 (file)
@@ -256,7 +256,7 @@ static void exit_dlls(void)
 static bool get_devinfo_data(struct libusb_context *ctx,
        HDEVINFO *dev_info, SP_DEVINFO_DATA *dev_info_data, const char *usb_class, unsigned _index)
 {
-       if (_index <= 0) {
+       if (_index == 0) {
                *dev_info = pSetupDiGetClassDevsA(NULL, usb_class, NULL, DIGCF_PRESENT|DIGCF_ALLCLASSES);
                if (*dev_info == INVALID_HANDLE_VALUE)
                        return false;
@@ -295,7 +295,7 @@ static SP_DEVICE_INTERFACE_DETAIL_DATA_A *get_interface_details(struct libusb_co
        SP_DEVICE_INTERFACE_DETAIL_DATA_A *dev_interface_details;
        DWORD size;
 
-       if (_index <= 0)
+       if (_index == 0)
                *dev_info = pSetupDiGetClassDevsA(guid, NULL, NULL, DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);
 
        if (dev_info_data != NULL) {
@@ -364,7 +364,7 @@ static SP_DEVICE_INTERFACE_DETAIL_DATA_A *get_interface_details_filter(struct li
        SP_DEVICE_INTERFACE_DETAIL_DATA_A *dev_interface_details;
        DWORD size;
 
-       if (_index <= 0)
+       if (_index == 0)
                *dev_info = pSetupDiGetClassDevsA(guid, NULL, NULL, DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);
 
        if (dev_info_data != NULL) {
index cdcaa78..55188bd 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11238
+#define LIBUSB_NANO 11239