Skip to contentSkip to conversation

easy-to-fix clang warnings

PATCH Superseded Philippe Mathieu-Daudé 3 participants 7 messages Mar 4, 2017 – Mar 5, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover easy-to-fix clang warnings

This patchset fixes three easy-to-fix clang warnings.

Philippe Mathieu-Daudé (3):
usb-ccid: make ccid_write_data_block() cope with null buffers
device_tree: fix compiler warnings (clang 5)
qga: fix compiler warnings (clang 5)

 device_tree.c                 | 1 +
 hw/usb/dev-smartcard-reader.c | 8 +++++++-
 qga/commands-posix.c          | 8 +++++---
 3 files changed, 13 insertions(+), 4 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/3 usb-ccid: make ccid_write_data_block() cope with null buffers

static code analyzer complain:

hw/usb/dev-smartcard-reader.c:816:5: warning: Null pointer passed as an argument to a 'nonnull' parameter

    memcpy(p->abData, data, len);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 hw/usb/dev-smartcard-reader.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/usb/dev-smartcard-reader.c +7 -1
index 757b8b3f5a..c38a4e5886 100644
@@ -799,8 +799,14 @@ static void ccid_write_parameters(USBCCIDState *s, CCID_Header *recv)
 static void ccid_write_data_block(USBCCIDState *s, uint8_t slot, uint8_t seq,
                                   const uint8_t *data, uint32_t len)
 {
-    CCID_DataBlock *p = ccid_reserve_recv_buf(s, sizeof(*p) + len);
+    CCID_DataBlock *p;
 
+    if (len == 0) {
+        return;
+    }
+    g_assert(data != NULL);
+
+    p = ccid_reserve_recv_buf(s, sizeof(*p) + len);
     if (p == NULL) {
         return;
     }
Signature · 1 line
2.11.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers

Quoted 10 lines · Philippe Mathieu-Daudé

static code analyzer complain:

hw/usb/dev-smartcard-reader.c:816:5: warning: Null pointer passed as an argument to a 'nonnull' parameter

    memcpy(p->abData, data, len);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer
Quoted 26 lines
---
 hw/usb/dev-smartcard-reader.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/usb/dev-smartcard-reader.c +7 -1
index 757b8b3f5a..c38a4e5886 100644
@@ -799,8 +799,14 @@ static void ccid_write_parameters(USBCCIDState *s,
 CCID_Header *recv)
 static void ccid_write_data_block(USBCCIDState *s, uint8_t slot, uint8_t
 seq,
                                   const uint8_t *data, uint32_t len)
 {
-    CCID_DataBlock *p = ccid_reserve_recv_buf(s, sizeof(*p) + len);
+    CCID_DataBlock *p;
 
+    if (len == 0) {
+        return;
+    }
+    g_assert(data != NULL);
+
+    p = ccid_reserve_recv_buf(s, sizeof(*p) + len);
     if (p == NULL) {
         return;
     }
Quoted 5 lines

--
2.11.0

--

Marc-André Lureau

#3 lore raw

PATCH 2/3 device_tree: fix compiler warnings (clang 5)

In reply to Philippe Mathieu-Daudé

static code analyzer complain:

device_tree.c:155:18: warning: Null pointer passed as an argument to a 'nonnull' parameter

    while ((de = readdir(d)) != NULL) {
                 ^~~~~~~~~~
Reported-by Clang Static Analyzer
---
 device_tree.c | 1 +
 1 file changed, 1 insertion(+)
device_tree.c +1 -0
index 6e06320830..a24ddff02b 100644
@@ -148,6 +148,7 @@ static void read_fstree(void *fdt, const char *dirname)
     d = opendir(dirname);
     if (!d) {
         error_setg(&error_fatal, "%s cannot open %s", __func__, dirname);
+        return;
     }
 
     while ((de = readdir(d)) != NULL) {
Signature · 1 line
2.11.0
#4 lore raw

PATCH 3/3 qga: fix compiler warnings (clang 5)

In reply to Philippe Mathieu-Daudé

static code analyzer complain:

qga/commands-posix.c:2127:9: warning: Null pointer passed as an argument to a 'nonnull' parameter

        closedir(dp);
        ^~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 qga/commands-posix.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
qga/commands-posix.c +5 -3
index ea37c097cf..9c4ef2d640 100644
@@ -2119,9 +2119,11 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,
          * we think this VM does not support online/offline memory block,
          * any other solution?
          */
-        if (!dp && errno == ENOENT) {
-            result->response =
-                GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+        if (!dp) {
+            if (errno == ENOENT) {
+                result->response =
+                    GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+            }
             goto out1;
         }
         closedir(dp);
Signature · 1 line
2.11.0
Reviewed-by on v1 3/3
#5 lore raw

Re: [Qemu-devel] [PATCH 3/3] qga: fix compiler warnings (clang 5)

Quoted 10 lines · Philippe Mathieu-Daudé

static code analyzer complain:

qga/commands-posix.c:2127:9: warning: Null pointer passed as an argument to a 'nonnull' parameter

        closedir(dp);
        ^~~~~~~~~~~~
Reported-by Clang Static Analyzer
Quoted 25 lines
---
 qga/commands-posix.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
qga/commands-posix.c +5 -3
index ea37c097cf..9c4ef2d640 100644
@@ -2119,9 +2119,11 @@ static void transfer_memory_block(GuestMemoryBlock
 *mem_blk, bool sys2memblk,
          * we think this VM does not support online/offline memory block,
          * any other solution?
          */
-        if (!dp && errno == ENOENT) {
-            result->response =
-                GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+        if (!dp) {
+            if (errno == ENOENT) {
+                result->response =
+
 GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+            }
             goto out1;
         }
         closedir(dp);
Quoted 5 lines

--
2.11.0

--

Marc-André Lureau

#6 lore raw
In reply to Philippe Mathieu-Daudé
Cc qemu-trivial
Quoted 11 lines · Philippe Mathieu-Daudé

This patchset fixes three easy-to-fix clang warnings.

Philippe Mathieu-Daudé (3):
usb-ccid: make ccid_write_data_block() cope with null buffers
device_tree: fix compiler warnings (clang 5)
qga: fix compiler warnings (clang 5)

 device_tree.c                 | 1 +
 hw/usb/dev-smartcard-reader.c | 8 +++++++-
 qga/commands-posix.c          | 8 +++++---
 3 files changed, 13 insertions(+), 4 deletions(-)